public void Put(string id, ShipmentDto dto) { _activityLog.Post(id, ActivityType.Update); var customer = _unitOfWork.Shipments.SingleOrDefault(w => w.Id == dto.Id); Mapper.Map(dto, customer); if (id != customer.Id) { return; } //customer.DateModified = DateTime.UtcNow; _unitOfWork.Shipments.Update(customer); try { _unitOfWork.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (_unitOfWork.Shipments.Any(e => e.Id == id)) { throw; } } }
private async Task SetShipmentDetailsAsync(ShipmentDto shipmentDto, bool isUpdate) { if (shipmentDto == null) { throw new InvalidServiceOperationException("Is null dto"); } if (string.IsNullOrEmpty(shipmentDto.OrderId)) { throw new InvalidServiceOperationException("Is null order id"); } var order = await GetEntityByIdAsync(shipmentDto.OrderId); _mapper.Map(shipmentDto, order); if (!isUpdate) { SetOrderedState(order); } await _orderDecorator.UpdateAsync(order); await _unitOfWork.CommitAsync(); }
/// <summary> /// Initializes a new instance of the <see cref="Shipment"/> class. /// </summary> /// <param name="dto">Dto to base the class on.</param> internal Shipment(ShipmentDto dto) { this.ShipmentId = dto.ShipmentId; this.IsTracked = dto.IsTracked; this.TrackingNumber = dto.TrackingNumber; this.TrackingUrl = new Uri(dto.TrackingUrl); this.EarliestEstimatedArrivalDate = dto.EarliestEstimatedArrivalDate; }
public async Task <ActionResult> Create_Post(ShipmentByAffiliateRequestModel requestModel) { if (ModelState.IsValid) { ShipmentDto shipment = await _shipmentsClient.AddShipmentAsync(requestModel); return(RedirectToAction("Details", new { id = shipment.Key })); } await GetAndSetShipmentTypesAsync(); return(View(requestModel)); }
public async Task <ActionResult> Edit_Post( Guid id, [Bind(Prefix = "ShipmentForEdit")] ShipmentByAffiliateUpdateRequestModel requestModel) { if (ModelState.IsValid) { ShipmentDto updatedShipment = await _shipmentsClient.UpdateShipmentAsync(id, requestModel); return(RedirectToAction("Details", new { id = updatedShipment.Key })); } ViewResult editViewResult = await GetEditViewResultAsync(id); return(editViewResult); }
private async Task <ViewResult> GetEditViewResultAsync(Guid id) { ShipmentDto shipment = await _shipmentsClient.GetShipmentAsync(id); var shipmentForEdit = new ShipmentByAffiliateUpdateRequestModel { Price = shipment.Price, ReceiverName = shipment.ReceiverName, ReceiverSurname = shipment.ReceiverSurname, ReceiverAddress = shipment.ReceiverAddress, ReceiverZipCode = shipment.ReceiverZipCode, ReceiverCity = shipment.ReceiverCity, ReceiverCountry = shipment.ReceiverCountry, ReceiverTelephone = shipment.ReceiverTelephone, ReceiverEmail = shipment.ReceiverEmail }; return(View(new ShipmentEditViewModel { Shipment = shipment, ShipmentForEdit = shipmentForEdit })); }
public async Task UpdateShipmentDetailsAsync(ShipmentDto shipmentDto) { const bool isUpdate = true; await SetShipmentDetailsAsync(shipmentDto, isUpdate); }
public IActionResult Put(string id, [FromBody] ShipmentDto value) { _service.Put(id, value); return(Ok()); }
public async Task <ShipmentDto> GetShipmentById(int id, int?customerId = null) { var lookup = new Dictionary <int, ShipmentDto>(); var lookupShipment = new Dictionary <int, List <int> >(); var lookupDetail = new Dictionary <int, List <int> >(); var lookupReceiverFacility = new Dictionary <int, List <int> >(); var lookupReceiverRequirement = new Dictionary <int, List <int> >(); var lookuptReceiverTruck = new Dictionary <int, List <int> >(); var lookupSenderFacility = new Dictionary <int, List <int> >(); var lookupSenderRequirement = new Dictionary <int, List <int> >(); using (IDbConnection cn = new SqlConnection(ConnectionString)) { cn.Open(); var item = await cn .QueryAsync <Shipment, ShipmentDetail, ShipmentReceiverFacility, ShipmentReceiverRequirement, ShipmentReceiverTruck, ShipmentSenderFacility, ShipmentSenderRequirement, ShipmentDto >(GetQuery(id, customerId), (shipment, shipmentDetail, shipmentReceiverFacility, shipmentReceiverRequirement, shipmentReceiverTruck, shipmentSenderFacility, shipmentSenderRequirement) => { ShipmentDto entity; if (!lookup.TryGetValue(shipment.Id, out entity)) { lookup.Add(shipment.Id, entity = new ShipmentDto()); entity.Shipment = shipment; } if (!lookupShipment.ExistsList(entity.Shipment.Id, shipment.Id)) { if (entity.Shipment == null) { entity.Shipment = new Shipment(); } entity.Shipment = shipment; } if (shipmentDetail != null) { if ( !lookupDetail.ExistsList(entity.Shipment.Id, shipmentDetail.Id)) { if (entity.ShipmentDetails == null) { entity.ShipmentDetails = new List <ShipmentDetail>(); } entity.ShipmentDetails.Add(shipmentDetail); } } if (shipmentReceiverFacility != null) { if ( !lookupReceiverFacility.ExistsList(entity.Shipment.Id, shipmentReceiverFacility.Id)) { if (entity.ShipmentReceiverFacilities == null) { entity.ShipmentReceiverFacilities = new List <ShipmentReceiverFacility>(); } entity.ShipmentReceiverFacilities.Add(shipmentReceiverFacility); } } if (shipmentReceiverRequirement != null) { if ( !lookupReceiverRequirement.ExistsList(entity.Shipment.Id, shipmentReceiverRequirement.Id)) { if (entity.ShipmentReceiverRequirements == null) { entity.ShipmentReceiverRequirements = new List <ShipmentReceiverRequirement>(); } entity.ShipmentReceiverRequirements.Add(shipmentReceiverRequirement); } } if (shipmentReceiverTruck != null) { if ( !lookuptReceiverTruck.ExistsList(entity.Shipment.Id, shipmentReceiverTruck.Id)) { if (entity.ShipmentReceiverTrucks == null) { entity.ShipmentReceiverTrucks = new List <ShipmentReceiverTruck>(); } entity.ShipmentReceiverTrucks.Add(shipmentReceiverTruck); } } if (shipmentSenderFacility != null) { if ( !lookupSenderFacility.ExistsList(entity.Shipment.Id, shipmentSenderFacility.Id)) { if (entity.ShipmentSenderFacilities == null) { entity.ShipmentSenderFacilities = new List <ShipmentSenderFacility>(); } entity.ShipmentSenderFacilities.Add(shipmentSenderFacility); } } if (shipmentSenderRequirement != null) { if ( !lookupSenderRequirement.ExistsList(entity.Shipment.Id, shipmentSenderRequirement.Id)) { if (entity.ShipmentSenderRequirements == null) { entity.ShipmentSenderRequirements = new List <ShipmentSenderRequirement>(); } entity.ShipmentSenderRequirements.Add(shipmentSenderRequirement); } } return(entity); }, "SplitDetail,SplitReceiverFacility,SplitReceiverRequirement,SplitReceiverTruck,SplitSenderFacility,SplitSenderRequirement"); } ShipmentDto result = lookup.Values.FirstOrDefault(); if (result != null) { ShipmentDto resultExtra = await GetShipmentExtraById(id, customerId); if (resultExtra != null) { if (resultExtra.ShipmentSenderTrucks != null) { result.ShipmentSenderTrucks = resultExtra.ShipmentSenderTrucks; } if (resultExtra.ShipmentTransporters != null) { result.ShipmentTransporters = resultExtra.ShipmentTransporters; } if (resultExtra.ShipmentReceiverAvailability != null) { result.ShipmentReceiverAvailability = resultExtra.ShipmentReceiverAvailability; } if (resultExtra.ShipmentSenderAvailability != null) { result.ShipmentSenderAvailability = resultExtra.ShipmentSenderAvailability; } } } return(result); }
public async Task <ShipmentDto> GetShipmentExtraById(int id, int?customerId) { var lookup = new Dictionary <int, ShipmentDto>(); var lookupShipment = new Dictionary <int, List <int> >(); var lookupSenderTruck = new Dictionary <int, List <int> >(); var lookupTransporter = new Dictionary <int, List <int> >(); var lookupReceiverAvailability = new Dictionary <int, List <int> >(); var lookupSenderAvailability = new Dictionary <int, List <int> >(); using (IDbConnection cn = new SqlConnection(ConnectionString)) { cn.Open(); var item = await cn .QueryAsync <Shipment, ShipmentSenderTruck, ShipmentTransporter, ShipmentReceiverAvailability, ShipmentSenderAvailability, ShipmentDto >(GetQueryExtra(id, customerId), (shipment, shipmentSenderTruck, shipmentTransporter, shipmentReceiverAvailability, shipmentSenderAvailability) => { ShipmentDto entity; if (!lookup.TryGetValue(shipment.Id, out entity)) { lookup.Add(shipment.Id, entity = new ShipmentDto()); entity.Shipment = shipment; } if (!lookupShipment.ExistsList(entity.Shipment.Id, shipment.Id)) { if (entity.Shipment == null) { entity.Shipment = new Shipment(); } entity.Shipment = shipment; } if (shipmentSenderTruck != null) { if (!lookupSenderTruck.ExistsList(entity.Shipment.Id, shipmentSenderTruck.Id)) { if (entity.ShipmentSenderTrucks == null) { entity.ShipmentSenderTrucks = new List <ShipmentSenderTruck>(); } entity.ShipmentSenderTrucks.Add(shipmentSenderTruck); ; } } if (shipmentTransporter != null) { if ( !lookupTransporter.ExistsList(entity.Shipment.Id, shipmentTransporter.Id)) { if (entity.ShipmentTransporters == null) { entity.ShipmentTransporters = new List <ShipmentTransporter>(); } entity.ShipmentTransporters.Add(shipmentTransporter); } } if (shipmentReceiverAvailability != null) { if ( !lookupReceiverAvailability.ExistsList(entity.Shipment.Id, shipmentReceiverAvailability.Id)) { if (entity.ShipmentReceiverAvailability == null) { entity.ShipmentReceiverAvailability = new List <ShipmentReceiverAvailability>(); } entity.ShipmentReceiverAvailability.Add(shipmentReceiverAvailability); } } if (shipmentSenderAvailability != null) { if ( !lookupSenderAvailability.ExistsList(entity.Shipment.Id, shipmentSenderAvailability.Id)) { if (entity.ShipmentSenderAvailability == null) { entity.ShipmentSenderAvailability = new List <ShipmentSenderAvailability>(); } entity.ShipmentSenderAvailability.Add(shipmentSenderAvailability); } } return(entity); }, "SplitSenderTruck,SplitTransporter,SplitReceiverAvailability,SplitSenderAvailability"); } return(lookup.Values.FirstOrDefault()); }
public async Task <ViewResult> Delete(Guid id) { ShipmentDto shipment = await _shipmentsClient.GetShipmentAsync(id); return(View(shipment)); }
public async Task <ActionResult> Details(Guid id) { ShipmentDto shipment = await _shipmentsClient.GetShipmentAsync(id); return(View(shipment)); }