public static DeliveryDto ToDto(this Delivery model) { var dto = new DeliveryDto { ID = model.ID, SupplierID = model.SupplierID, Supplier = model.Supplier?.ToDto(), LocationID = model.LocationID, Location = model.DeliveryLocation?.ToDto(), BillNumber = model.BillNumber, DeliveryDate = model.DeliveryDate, PaymentDate = model.PaymentDate, DollarRate = model.DollarRate, EuroRate = model.EuroRate, TotalGrossPrice = model.TotalGrossPrice, TotalDiscount = model.TotalDiscount, TotalDiscountedPrice = model.TotalDiscountedPrice, IsSubmitted = model.IsSubmitted, ItemsCount = model.Items?.Count ?? 0, Items = model.Items?.Where(di => !di.IsDeleted).Select(i => i.ToDto()) }; dto.MapDetails(model); dto.CanBeDeleted = !(model.IsSubmitted || model.IsDeleted); return(dto); }
public DeliveryReceiptPdf(DeliveryDto receipt, InventorySummary inventorySummary, string fileNameDrTemplate) : base(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false), PageSize.LETTER.Rotate()) { deliveryReceipt = receipt; fileNameTemplate = fileNameDrTemplate; this.inventorySummary = inventorySummary; }
public DeliveryDto New(int jobID, int empid) { string name = ctx.Employee.Find(empid).firstname + ' ' + ctx.Employee.Find(empid).lastname; JobSite jobsite = ctx.JobSite.Where(p => p.JobID == jobID).FirstOrDefault(); Delivery newEntity = new Delivery { JobID = jobID, JobSiteID = jobsite.JobSiteID, DeliveryDate = DateTime.Now, EmployeeID = empid }; ctx.Delivery.Add(newEntity); ctx.SaveChanges(); DeliveryDto dto = new DeliveryDto { JobID = newEntity.JobID, DeliveryDate = newEntity.DeliveryDate, EmployeeID = newEntity.EmployeeID, DriverName = name, JobSiteID = newEntity.JobSiteID }; return(dto); }
public DeliveryDto Update(DeliveryDto delivery) { var delvery = mapper.Map<Delivery.Core.Delivery>(delivery); var updatedDelvery = _delviryRepository.Update(delvery); _unitOfWork.Commit(); return mapper.Map<DeliveryDto>(updatedDelvery); }
public void ToExpectMapAllProperties() { var dto = new DeliveryDto { Id = "expectedId", Recipient = new RecipientDto(), AccessWindow = new AccessWindowDto(), Order = new OrderDto(), State = DeliveryState.Completed }; var expectedRecipient = new Recipient(); _mockRecipientMapper.Setup(mapper => mapper.To(dto.Recipient)).Returns(expectedRecipient); var expectedAccessWindow = new AccessWindow(); _mockAccessWindowMapper.Setup(mapper => mapper.To(dto.AccessWindow)).Returns(expectedAccessWindow); var expectedOrder = new Order(); _mockOrderMapper.Setup(mapper => mapper.To(dto.Order)).Returns(expectedOrder); var actual = _deliveryMapper.To(dto); Assert.NotNull(actual); Assert.Equal(dto.Id, actual.Id); Assert.Equal(expectedOrder, actual.Order); Assert.Equal(expectedRecipient, actual.Recipient); Assert.Equal(expectedAccessWindow, actual.AccessWindow); Assert.Equal(dto.State, actual.State); }
public static Delivery ToEntity(this DeliveryDto dto) { var entity = new Delivery { ID = dto.ID, SupplierID = dto.SupplierID, LocationID = dto.LocationID, BillNumber = dto.BillNumber, DeliveryDate = dto.DeliveryDate, PaymentDate = dto.PaymentDate, DollarRate = dto.DollarRate, EuroRate = dto.EuroRate, TotalGrossPrice = dto.TotalGrossPrice, TotalDiscount = dto.TotalDiscount, TotalDiscountedPrice = dto.TotalDiscountedPrice, IsSubmitted = dto.IsSubmitted, Items = dto.Items?.Select(i => i.ToEntity()).ToList(), Recommendations = dto.Recommendations?.Select(r => r.ToEntity()).ToList(), Attachments = dto.Attachments?.Select(a => a.ToEntity()).ToList() }; if (!string.IsNullOrEmpty(dto.MainPicture?.FullPath)) { entity.Attachments.Add(dto.MainPicture.ToEntity()); } return(entity); }
public async Task <ServiceResponse <int> > CreateAsync(DeliveryDto delivery, int userId) { if (delivery == null) { throw new ArgumentNullException(nameof(delivery)); } var entity = delivery.ToEntity(); entity.UpdateCreatedFields(userId).UpdateModifiedFields(userId); var supplier = await UnitOfWork.Get <Supplier>().GetAsync(s => s.ID == delivery.SupplierID); supplier.UpdateModifiedFields(userId); var location = await UnitOfWork.Get <Location>().GetAsync(l => l.ID == delivery.LocationID); location.UpdateModifiedFields(userId); entity.Recommendations?.UpdateCreatedFields(userId).UpdateModifiedFields(userId); entity.Attachments?.UpdateCreatedFields(userId).UpdateModifiedFields(userId); var saved = UnitOfWork.Get <Delivery>().Add(entity); await UnitOfWork.SaveAsync(); return(new SuccessResponse <int>(saved.ID)); }
public async Task UpdateChangeForStateIsNotAllowed() { const Role expectedRole = Role.Partner; _mockExecutionContext.SetupGet(executionContext => executionContext.UserRole).Returns(expectedRole); const string expectedId = "expectedId"; const DeliveryState newState = DeliveryState.Approved; var expectedDto = new DeliveryDto { Id = expectedId, State = newState }; const DeliveryState oldState = DeliveryState.Created; var existedDelivery = new Delivery { Id = expectedId, State = oldState }; _mockRepo.Setup(repo => repo.Get(expectedId)).Returns(Task.FromResult(existedDelivery)); _mockPermissionChecker.Setup(checker => checker.RoleHasChangePermission(expectedRole, oldState, newState)).Returns(false); await Assert.ThrowsAsync <UnauthorizedException>(async() => await _deliveryService.Update(_mockExecutionContext.Object, expectedDto)); }
public ComprobanteDelivery(long id) : this(new DeliveryServicio(), new ArticuloServicio(), new EmpleadoServicio(), new ClienteServicio()) { InitializeComponent(); comprobante = _deliveryServicio.ObtenerPorId(id); _edicion = true; ActualizarGrilla(); }
public async Task <DeliveryDto> Update(IExecutionContext executionContext, DeliveryDto entity) { AssertExecutionContext(executionContext); if (entity == null) { throw new ArgumentNullException(nameof(entity)); } var existedEntity = await _deliveryRepo.Get(entity.Id); if (existedEntity == null) { return(null); } var oldState = existedEntity.State; var newState = entity.State; if (!_permissionChecker.RoleHasChangePermission(executionContext.UserRole, oldState, newState)) { throw new UnauthorizedException( $"This role has no permission to change the role from {oldState} to {newState}"); } var dbEntity = await _deliveryRepo.Update(_deliveryMapper.To(entity)); return(_deliveryMapper.From(dbEntity)); }
/// <summary>Returns the PowerOffice customer code of the organisation that this delivery is associated with. Returns `null` if the code couldn't be found. This can happen if the organisation doesn't exist in PowerOffice.</summary> private async Task <long?> GetPowerofficeCustomerCode( DeliveryDto webcrmDelivery) { if (!webcrmDelivery.DeliveryOrganisationId.HasValue) { throw new ApplicationException("Cannot get PowerOffice organisation ID since DeliveryOrganisationId is null."); } var webcrmOrganisation = await WebcrmClient.GetOrganisationById(webcrmDelivery.DeliveryOrganisationId.Value); long?powerofficeOrganisationId = webcrmOrganisation.GetPowerofficeOrganisationId(Configuration.OrganisationIdFieldName); if (!powerofficeOrganisationId.HasValue) { return(null); } var powerofficeOrganisation = await PowerofficeClient.GetCustomer(powerofficeOrganisationId.Value); if (powerofficeOrganisation == null) { throw new ApplicationException($"Could not find a PowerOffice organisation with ID {powerofficeOrganisationId.Value}."); } if (!powerofficeOrganisation.Code.HasValue) { throw new ApplicationException("PowerOffice organisation code is null."); } return(powerofficeOrganisation.Code.Value); }
public DeliveryDto Add(DeliveryDto delivery) { delivery.Id = Guid.NewGuid(); var Newdelvery = mapper.Map<Delivery.Core.Delivery>(delivery); var delvery = _delviryRepository.Add(Newdelvery); _unitOfWork.Commit(); return mapper.Map<DeliveryDto>(delivery); }
/// <summary>Updates this delivery based on a webCRM delivery, excluding the delivery lines.</summary> protected void UpdateExcludingLines( DeliveryDto webcrmDelivery, long powerofficeCustomerCode) { CustomerCode = powerofficeCustomerCode; OrderDate = webcrmDelivery.DeliveryOrderDate; Status = OutgoingInvoiceStatus.Approved; }
public UpsertDeliveryToFortnoxPayload( DeliveryDto webcrmDelivery, List <QuotationLineDto> webcrmDeliveryLines, string webcrmSystemId) : base(webcrmSystemId) { WebcrmDelivery = webcrmDelivery; WebcrmDeliveryLines = webcrmDeliveryLines; }
private void AssignDefaultPrice(DeliveryDto deliveryDto) { deliveryDto.SlimUnitPrice = LookupDataManager.ProductTypes.First(x => x.ProductTypeId == DataConstants.ProductTypes.Slim).BasePrice; deliveryDto.SlimAmount = deliveryDto.SlimUnitPrice * deliveryDto.SlimQty; deliveryDto.RoundUnitPrice = LookupDataManager.ProductTypes.First(x => x.ProductTypeId == DataConstants.ProductTypes.Round).BasePrice; deliveryDto.RoundAmount = deliveryDto.RoundUnitPrice * deliveryDto.RoundQty; }
public Task UpdateDeliveryAsync(DeliveryDto dto) => GetConnectionAsync(con => con.ExecuteAsync(@" UPDATE Delivery SET MagicItemId = @MagicItemId AccountId = @AccountId Quantity = @Quantity Completed = @Completed WHERE DeliveryId = @DeliveryId", dto));
public DeliveryDto FindDelivery(int deliveryID) { var entity = ctx.Delivery.AsNoTracking().Include(j => j.Job) .Include(s => s.JobSite).Include(e => e.Employee) .Include(i => i.DeliveryItem).Where(d => d.DeliveryID == deliveryID).FirstOrDefault(); DeliveryDto Dto = new DeliveryDto(); deliveryMapper.Map(entity, Dto); return(Dto); }
public async Task <ServiceResponse <DeliveryDto> > UpdateAsync(DeliveryDto delivery, int userId) { if (delivery == null) { throw new ArgumentNullException(nameof(delivery)); } var existentEntity = await UnitOfWork.Get <Delivery>().GetAsync(d => d.ID == delivery.ID, d => d.Items); if (existentEntity == null) { return(new ServiceResponse <DeliveryDto>(ServiceResponseStatus.NotFound)); } var entity = delivery.ToEntity(); existentEntity.Attachments = GetAttachments(existentEntity.ID).ToList(); existentEntity.Recommendations = GetRecommendations(existentEntity.ID).ToList(); existentEntity .UpdateFields(entity) .UpdateAttachments(entity, UnitOfWork, userId) .UpdateRecommendations(entity, UnitOfWork, userId) .UpdateModifiedFields(userId); if (entity.IsSubmitted) { foreach (var item in existentEntity.Items) { for (var i = 0; i < item.Quantity; i++) { var goods = new Goods(); goods.UpdateCreatedFields(userId).UpdateModifiedFields(userId); var storage = new Storage { LocationID = delivery.LocationID, FromDate = DateTime.Now }; storage.UpdateCreatedFields(userId).UpdateModifiedFields(userId); goods.Storages.Add(storage); item.Goods.Add(goods); } } } UnitOfWork.Get <Delivery>().Update(existentEntity); await UnitOfWork.SaveAsync(); return(new SuccessResponse <DeliveryDto>()); }
public async Task UpdateExceptionHappenedExpectBadRequestResult() { var deliveryDto = new DeliveryDto(); _mockDeliveryService.Setup(service => service.Update(_mockExecutionContext.Object, deliveryDto)) .Throws <Exception>(); var result = await _deliveriesController.Update("expectedId", deliveryDto); Assert.IsType <BadRequestResult>(result); }
public IHttpActionResult CreateFractionedDelivery([FromBody] DeliveryDto fractionedDeliveryDto) { try { return(Ok(_createDeliveryBusiness.CreateFractionedDelivery(fractionedDeliveryDto))); } catch (Exception e) { return(InternalServerError(e)); } }
public async Task <bool> Remove(DeliveryDto deliveryDto) { try { var delivery = _mapper.Map <Delivery>(deliveryDto); return(await _service.Remove(delivery)); } catch (Exception ex) { throw ex; } }
public async Task <IHttpActionResult> StartDelivery(Guid courierId, DeliveryDto delivery) { foreach (var order in delivery.Orders) { await OrderService.ChangeOrderStateAsync(order, OrderStateDto.Fulfillment); } await RouteService.AddRouteAsync(courierId, delivery.Route); await CourierService.ChangeCourierStateAsync(courierId, CourierStateDto.PerformsDelivery); return(Ok()); }
public Response Post(DeliveryDto model) { if (ModelState.IsValid) { return(_inventoryService.Add(model)); } return(new Response { IsSuccess = false, Errors = new Error("", "اطلاعات ورودی صحیح نمی باشد"), }); }
public async Task CopyDeliveryToPoweroffice( DeliveryDto webcrmDelivery, List <QuotationLineDto> webcrmDeliveryLines) { Guid?powerofficeDeliveryId = webcrmDelivery.GetPowerofficeDeliveryId(Configuration.DeliveryIdFieldName); if (powerofficeDeliveryId == null) { long?powerofficeCustomerCode = await GetPowerofficeCustomerCode(webcrmDelivery); if (!powerofficeCustomerCode.HasValue) { Logger.LogInformation($"Not copying webCRM delivery with ID {webcrmDelivery.DeliveryId} to PowerOffice because the corresponding PowerOffice organisation could not be found."); return; } Logger.LogTrace("Copying delivery to PowerOffice, creating a new one."); var newPowerofficeDelivery = new NewOutgoingInvoice(webcrmDelivery, webcrmDeliveryLines, powerofficeCustomerCode.Value, Configuration.ProductIdFieldName); var createdPowerofficeDelivery = await PowerofficeClient.CreateInvoice(newPowerofficeDelivery); webcrmDelivery.SetPowerofficeDeliveryId(Configuration.DeliveryIdFieldName, createdPowerofficeDelivery.Id); await WebcrmClient.UpdateDelivery(webcrmDelivery); if (createdPowerofficeDelivery.OutgoingInvoiceLines.Count != webcrmDeliveryLines.Count) { throw new ApplicationException($"Sanity check failed: Expected the same number of lines in newly created PowerOffice delivery. Lines in webCRM delivery: {webcrmDeliveryLines.Count}. Lines in PowerOffice delivery: {createdPowerofficeDelivery.OutgoingInvoiceLines.Count}."); } } else { var matchingPowerofficeDelivery = await PowerofficeClient.GetInvoice(powerofficeDeliveryId.Value); if (matchingPowerofficeDelivery == null) { Logger.LogWarning($"Could not find PowerOffice delivery (invoice) with id {powerofficeDeliveryId.Value}. Not copying the delivery to PowerOffice."); return; } // Not comparing the two deliveries, since we're only synchronising deliveries one way. long?powerofficeCustomerCode = await GetPowerofficeCustomerCode(webcrmDelivery); if (!powerofficeCustomerCode.HasValue) { Logger.LogInformation($"Not copying webCRM delivery with ID {webcrmDelivery.DeliveryId} to PowerOffice because the corresponding PowerOffice organisation could not be found."); return; } Logger.LogTrace("Copying delivery to PowerOffice, updating an existing one."); matchingPowerofficeDelivery.UpdateIncludingLines(webcrmDelivery, webcrmDeliveryLines, powerofficeCustomerCode.Value, Configuration.ProductCodeFieldName); await PowerofficeClient.UpdateInvoice(matchingPowerofficeDelivery); } }
public NewOutgoingInvoice( DeliveryDto webcrmDelivery, List <QuotationLineDto> webcrmDeliveryLines, long powerofficeCustomerCode, string productCodeFieldName) : this() { UpdateExcludingLines(webcrmDelivery, powerofficeCustomerCode); OutgoingInvoiceLines = webcrmDeliveryLines .Select(webcrmLine => new OutgoingInvoiceLine(webcrmLine, productCodeFieldName)) .ToList(); }
private void UpdateOrderStatus(DeliveryDto deliveryDto) { if (deliveryDto.OrderId != null) { var order = orderService.Get(deliveryDto.OrderId.Value); if (order != null) { var orderDto = Mapper.Map <OrderDto>(order); order.OrderStatusId = orderDto.CalculatedStatusId; orderService.Update(order); } } }
public ActionResult Save(DeliveryDto model) { if (ModelState.IsValid) { var Delivery = new Delivery(); _Delivery.Save(model); return(RedirectToAction("List")); } else { return(RedirectToAction("Create", model)); } }
public async Task <DeliveryDto> Update(DeliveryDto deliveryDto) { try { var delivery = _mapper.Map <Delivery>(deliveryDto); var result = await _service.Update(delivery); return(_mapper.Map <DeliveryDto>(result)); } catch (Exception ex) { throw ex; } }
public ComprobanteDelivery(IDeliveryServicio deliveryServicio, IArticuloServicio articuloServicio, IEmpleadoServicio empleadoServicio, IClienteServicio clienteServicio) { if (comprobante == null) { comprobante = new DeliveryDto(); } _clienteServicio = clienteServicio; _deliveryServicio = deliveryServicio; _empleadoServicio = empleadoServicio; _articuloServicio = articuloServicio; }
public static Delivery CreateEntity(this DeliveryDto deliveryDto) { return(new Delivery() { DeliveryId = deliveryDto.deliveryId, DateDelivery = deliveryDto.dateDelivery, ClientId = deliveryDto.clientId, ProductType = deliveryDto.productType, QuantityProduct = deliveryDto.quantityProduct, DeliveriesTruckTips = deliveryDto.deliveriesTruckTips?.CreateEntity(), Client = deliveryDto.client?.CreateEntity(), Address = deliveryDto.address?.CreateEntity() }); }