Notes
Notes - notes.io |
{
StepStatusGetAllResponse response = new();
var request = await _requestRepository
.GetFirstAsyncWithIncludeList(x => x.Id == requestId, isTrack: false, new string[] { "VehicleInformations",
"RequestAttachments",
"RequestSteps",
"RequestReviews",
"User"});
var notificationStep = NotificationStatus.Sent;
switch (request.Status)
{
case RequestStatus.Rejected:
throw new BadRequestException("Request rejected");
case RequestStatus.InComplete:
throw new BadRequestException("Request not completed");
case RequestStatus.Completed:
request.Status = RequestStatus.Watching_Ayna;
break;
case RequestStatus.Returned:
throw new BadRequestException("Request send for fix");
default:
break;
}
var userPolicy = await GetUserPolicy();
bool isAuthorized = CheckRoleAuthorization(userPolicy.Policy.Name, stepType);
if (!isAuthorized) throw new UnauthorizedAccessException("Your have not permission this operation!");
var requestStep = request.RequestSteps.FirstOrDefault(x => x.Step == stepType.ToString());
if (requestStep is null) throw new BadRequestException("Step not found");
var requestStepOperator = request.RequestSteps.FirstOrDefault(x => x.Step == StepType.aynaoperator_checking.ToString());
if (requestStepOperator == null)
throw new BadRequestException("The request has not been accepted by any operator");
var requestStepSupervisor = GetSpecificStep(stepType, request, StepType.supervisor_checking);
var requestStepGuidance = GetSpecificStep(stepType, request, StepType.guidance_checking);
var requestStepAyda = GetSpecificStep(stepType, request, StepType.aayda_checking);
var requestStepDin = GetSpecificStep(stepType, request, StepType.dindypi_checking);
var userOperator = await _userRequestStepRepository.GetFirstAsyncWithInclude(x => x.RequestId == request.Id && x.RequestStepId == requestStepOperator.Id, "User");
if (userOperator == null) throw new NotFoundException("Operator not found");
var initialStep = request.RequestSteps.FirstOrDefault(x => x.Step == StepType.aynaoperator_checking.ToString());
int initialOrder = initialStep.Order;
int maxOrder = request.RequestSteps.Max(rs => rs.Order);
for (int i = maxOrder; i >= initialOrder; i--)
{
UpdateRequestStepOrder(request.RequestSteps, i, i + 1);
}
string message = $"{requestId} nömrəli müraciət düzəliş üçün daşıyıcıya göndərildi.";
var newRequestStep = new RequestStep
{
Request = request,
Status = RequestStepStatus.Pending,
Order = initialOrder
};
switch (stepType)
{
case StepType.dindypi_checking:
newRequestStep.Step = StepType.din_sent_for_fix.ToString();
message = $"{requestId} nömrəli müraciət DIN BDYPI tərəfindən düzəliş üçün göndərildi.";
break;
case StepType.aayda_checking:
newRequestStep.Step = StepType.aayda_sent_for_fix.ToString();
message = $"{requestId} nömrəli müraciət AAYDA tərəfindən düzəliş üçün göndərildi.";
break;
case StepType.supervisor_checking:
initialStep.Status = RequestStepStatus.Pending;
newRequestStep.Step = StepType.supervisor_sent_for_fix.ToString();
message = $"Nəzarətçi {requestId} nömrəli müraciəti düzəliş etməyiniz üçün qaytardı.";
break;
case StepType.guidance_checking:
initialStep.Status = RequestStepStatus.Pending;
newRequestStep.Step = StepType.guidance_sent_for_fix.ToString();
message = $"Rəhbər {requestId} nömrəli müraciəti düzəliş etməyiniz üçün qaytardı.";
break;
default:
newRequestStep.Step = StepType.operator_sent_for_fix.ToString();
request.SendDate = _dateTime.Now;
notificationStep = NotificationStatus.Forfix;
request.Status = RequestStatus.Returned;
break;
}
var requestFix = request.RequestSteps.FirstOrDefault(x => x.Step == newRequestStep.Step);
if (requestFix != null && requestFix.Status == RequestStepStatus.Pending) throw new BadRequestException("Request already sent for fix");
newRequestStep.Description = message;
request.RequestSteps.Add(newRequestStep);
await _requestRepository.UpdateAsync(request);
if (stepType == StepType.supervisor_checking)
{
var userSupervisor = await _userRequestStepRepository.GetFirstAsyncWithInclude(x => x.RequestId == requestId && x.RequestStepId == requestStepSupervisor.Id, "User");
if (userSupervisor == null) throw new NotFoundException("Supervisor not found");
await _notificationRepository.AddAsync(new Notification
{
Message = $"Siz {requestId} nömrəli müraciəti düzəliş üçün operatora göndərdiniz.",
Status = NotificationStatus.NotSeen,
Step = notificationStep,
CreatedDate = _dateTime.Now,
SendAt = _dateTime.Now,
User = userSupervisor.User,
UserId = userSupervisor.UserId
});
}
if (stepType == StepType.guidance_checking)
{
var userGuidance = await _userRequestStepRepository.GetFirstAsyncWithInclude(x => x.RequestId == requestId && x.RequestStepId == requestStepGuidance.Id, "User");
if (userGuidance == null) throw new NotFoundException("Guidance not found");
await _notificationRepository.AddAsync(new Notification
{
Message = $"Siz {requestId} nömrəli müraciəti düzəliş üçün operatora göndərdiniz. ",
Status = NotificationStatus.NotSeen,
Step = notificationStep,
CreatedDate = _dateTime.Now,
SendAt = _dateTime.Now,
User = userGuidance.User,
UserId = userGuidance.UserId
});
}
await _notificationRepository.AddAsync(new Notification
{
Message = message,
Status = NotificationStatus.NotSeen,
Step = notificationStep,
CreatedDate = _dateTime.Now,
SendAt = _dateTime.Now,
User = userOperator.User,
UserId = userOperator.UserId
});
if (request.Status == RequestStatus.Returned)
{
await _notificationRepository.AddAsync(new Notification
{
Message = $"{requestId} nömrəli müraciətiniz düzəliş etməyiniz üçün qaytarıldı.",
Status = NotificationStatus.NotSeen,
Step = notificationStep,
CreatedDate = _dateTime.Now,
SendAt = _dateTime.Now,
UserId = request.UserId
});
}
var dto = Mapper.Map<ICollection<RequestStepDto>>(request.RequestSteps.OrderBy(x => x.Order));
response.RequestStepDtos = dto;
return response;
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team