NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

public async Task<RequestResponse> ChangeRequest(int requestId, RequestAccidentRequest requestAccidentRequest)
{
using TransactionScope scope = new(TransactionScopeAsyncFlowOption.Enabled);
try
{
bool isChanged = false;
bool checkRouteDiff = false;
var existingRequest = await GetRequestByIdWithNoTracking(requestId);
var userPolicy = await _userService.GetUserPolicy();
if (userPolicy.Policy.Name != nameof(Policies.Carrier) || userPolicy.UserId != existingRequest.UserId)
throw new BadRequestException("Sizin bu əməliyyatı yerinə yetirmək səlahiyyətiniz yoxdur");
var accidentStep = existingRequest.RequestSteps.FirstOrDefault(x => x.Step == StepType.user_request_accident_or_change.ToString()
&& x.Status == RequestStepStatus.Pending);
if (accidentStep == null)
throw new BadRequestException("Müraciət qəza və ya marşrut dəyişmə əməliyyatı üçün göndərilməmişdir");
existingRequest.AynaStatus = AynaStatus.Pending;

var lastDetail = existingRequest.RouteDetail?.LastOrDefault();
if (lastDetail == null) throw new BadRequestException("Məlumat tapılmadı");

if (!string.IsNullOrEmpty(requestAccidentRequest.StartPoint) &&
!string.IsNullOrEmpty(requestAccidentRequest.EndPoint) && requestAccidentRequest.TripCount != null)
{
if (string.IsNullOrEmpty(requestAccidentRequest.StartPoint) ||
string.IsNullOrEmpty(requestAccidentRequest.EndPoint) || requestAccidentRequest.TripCount == null)
{
throw new BadRequestException("Marşrut tam qeyd edilməyib");
}
checkRouteDiff = lastDetail.StartPoint != requestAccidentRequest.StartPoint || lastDetail.EndPoint != requestAccidentRequest.EndPoint;
existingRequest.RouteDetail?.Add(new RouteDetail
{
StartPoint = requestAccidentRequest.StartPoint,
EndPoint = requestAccidentRequest.EndPoint,
TripCount = requestAccidentRequest.TripCount,
IsOld = false
});
lastDetail = existingRequest.RouteDetail?.LastOrDefault();
}

if (lastDetail?.IsOld == true)
{
//isChanged = true;
existingRequest.RouteDetail?.Add(new RouteDetail
{
StartPoint = requestAccidentRequest.StartPoint,
EndPoint = requestAccidentRequest.EndPoint,
TripCount = requestAccidentRequest.TripCount,
IsOld = false
});
}
else
{
lastDetail.StartPoint = requestAccidentRequest.StartPoint == null ? lastDetail.StartPoint : requestAccidentRequest.StartPoint;
lastDetail.EndPoint = requestAccidentRequest.EndPoint == null ? lastDetail.EndPoint : requestAccidentRequest.EndPoint;
lastDetail.TripCount = requestAccidentRequest.TripCount == null ? lastDetail.TripCount : requestAccidentRequest.TripCount;
}

// Handle new attachments and vehicle information

if (requestAccidentRequest.RequestAttachments != null && requestAccidentRequest.RequestAttachments.Any())
{
List<SaveRequestAttachmentRequest> data = requestAccidentRequest.RequestAttachments.Where(x => !x.IsOld).ToList();
if (data != null && data.Any())
{
if (data.Count() > 2) isChanged = true;
foreach (var newFile in data)
{
var file = existingRequest.RequestAttachments?.FirstOrDefault(x => !x.IsOld);
var id = file != null ? file.UniqueId : Guid.NewGuid();
await _attachmentService.AttachmentHandle(existingRequest, newFile, id);
}
}
}
if (requestAccidentRequest.VehicleInformations != null)
{
bool checkDiff = false;
var vehicleInfo = existingRequest.VehicleInformations?.OrderBy(x => x.Id).LastOrDefault();
var reqVehicle = requestAccidentRequest.VehicleInformations.Where(x => !x.IsOld).FirstOrDefault();
if (reqVehicle != null)
{
checkDiff = !requestAccidentRequest.VehicleInformations.Where(x => !x.IsOld)
.Any(requestVehicle =>
requestVehicle.Height == vehicleInfo.Height &&
requestVehicle.Width == vehicleInfo.Width &&
requestVehicle.Length == vehicleInfo.Length &&
requestVehicle.AxlesInfo.AxlesSpacing?.Count() == vehicleInfo.AxlesInfo.AxlesSpacing?.Count() &&
requestVehicle.AxlesInfo.AxlesLoad?.Count() == vehicleInfo.AxlesInfo.AxlesLoad?.Count() &&
requestVehicle.AxlesInfo.AxlesSpacing.SequenceEqual(vehicleInfo.AxlesInfo.AxlesSpacing) &&
requestVehicle.AxlesInfo.AxlesLoad.SequenceEqual(vehicleInfo.AxlesInfo.AxlesLoad) &&
requestVehicle.LoadWeight == vehicleInfo.LoadWeight &&
requestVehicle.TrailerInformations?.Count() == vehicleInfo.TrailerInformations.Count() &&
requestVehicle.CarrierMass == vehicleInfo.CarrierMass);
}

if (checkDiff || checkRouteDiff)
{
isChanged = true;
var updatedVehicleInfos = existingRequest.VehicleInformations;
foreach (var vehicleInformation in existingRequest.VehicleInformations)
{
if (!vehicleInformation.IsEditable)
requestAccidentRequest.VehicleInformations.Remove(Mapper.Map<VehicleInformationRequest>(vehicleInformation));
}
await ClearExistingVehicleInformation(existingRequest);
foreach (var newVehicle in requestAccidentRequest.VehicleInformations)
{
var newVehicleInfo = Mapper.Map<VehicleInformation>(newVehicle);
newVehicleInfo.IsEditable = true;
updatedVehicleInfos.Add(newVehicleInfo);
}

existingRequest.VehicleInformations = updatedVehicleInfos;
await ChangeRequestStepStatusToPending(existingRequest);
}
else
{
var operatorStep = existingRequest.RequestSteps.FirstOrDefault(x => x.Step == StepType.aynaoperator_checking.ToString());
operatorStep.Status = RequestStepStatus.Pending;
}
}
existingRequest.IsChanged = isChanged;
await _requestRepository.UpdateAsync(existingRequest);
await _notificationRepository.AddAsync(new Notification
{
Message = $" Müraciətiniz yadda saxlanıldı.",
Status = NotificationStatus.NotSeen,
Step = NotificationStatus.Saved,
CreatedDate = _dateTime.Now,
SendAt = _dateTime.Now,
User = existingRequest.User,
UserId = existingRequest.UserId,
RequestId = existingRequest.Id
});
scope.Complete();
return new RequestResponse { Success = true };
}
catch (Exception e)
{
throw new BadRequestException(e.Message);
}
}
     
 
what is notes.io
 

Notes is a web-based application for online 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 14 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

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.