public async Task <IServiceResult> CreateAsync(ShippingDto shippingDto) { try { var shipping = _mapper.Map <ShippingDto, Shipping>(shippingDto); await _repository.AddAsync(shipping); if (!await _unitOfWork.CompleteAsync()) { throw new SaveFailedException(nameof(shipping)); } _logger.LogInformation( $"Added new shippng with id: {shipping.Id} for order with id: {shipping.OrderId}."); var result = await GetSingleAsync(shipping.Id.ToString()); return(new ServiceResult(payload: result.Payload)); } catch (Exception e) { _logger.LogError($"Adding new shipping failed. {e.Message}"); return(new ServiceResult(false, e.Message)); } }
public async Task <IServiceResult> UpdateAsync(string id, ShippingDto shippingDto) { try { var shippingId = id.ToGuid(); var shipping = await _repository.GetSingleAsync(shippingId); _mapper.Map(shippingDto, shipping); if (!await _unitOfWork.CompleteAsync()) { throw new SaveFailedException(nameof(shipping)); } _logger.LogInformation($"Updated {nameof(shipping)} with id: {shipping.Id} for order with id: {shipping.OrderId}"); var result = await GetSingleAsync(shipping.Id.ToString()); return(new ServiceResult(payload: result.Payload)); } catch (Exception e) { _logger.LogError($"Updating shipping with id: {id} failed. {e.Message}"); return(new ServiceResult(false, e.Message)); } }
public async Task <ActionResult <ShippingDto> > CreateShipping(ShippingDto shippingDto) { var po = await _erpRepository.GetReceivingByPO(shippingDto.PONumber.ToUpper()); if (po.VendorNo != shippingDto.VenderNo) { return(BadRequest("Invalid PO or Vender Number.")); } var shipping = _mapper.Map <Shipping>(shippingDto); shipping.Vender = await _venderRepository.GetVenderByNumber(shippingDto.VenderNo.ToUpper()); shipping.User = await _userManager.FindByEmailAsync(shippingDto.UserEmail); shipping.ShippingNumber = "SN" + _shippingRepository.LotCountAsync().ToString().PadLeft(7, '0'); shipping.ShippingMethod = await _venderRepository.GetShippingMethodbyName(shippingDto.LogisticName.ToUpper()); var lot = new ShippingLot { LotNumber = "LOT" + shippingDto.ArrivalDate.ToString("MMddyyyy") + shipping.ShippingNumber, CreateTime = shippingDto.ArrivalDate }; _shippingRepository.CreateShippingLot(lot); shipping.ShippingLot = lot; _shippingRepository.AddShippingAsync(shipping); if (await _shippingRepository.SaveAllAsync()) { return(Ok(shipping)); } return(BadRequest("Failed to add shipping.")); }
public async Task CreateShippingAsync(ShippingDtoMessage message) { var order = await _db.Orders .Include(x => x.Items) .Include(x => x.Customer) .FirstOrDefaultAsync(x => x.Id == message.OrderId); var dto = new ShippingDto { Id = order.Id, Number = order.Number, Status = order.Status, CreateDate = order.CreateDate, Customer = new ShippingDto.CustomerDetail() { Id = order.Customer.Id, Name = order.Customer.Name, Address = order.Customer.Address } }; foreach (var item in order.Items) { var itemDto = new ShippingDto.OrderItemDetail() { Id = item.Id, Name = item.Name, Price = item.Price, Quantity = item.Quantity, Total = item.Total }; dto.Items.Add(itemDto); } await _bus.PublishAsync(ExchangeNames.DTO, dto); }
/// <summary> /// Genera el json en la solapa resultado a partir de los datos ingresados en el resto de las solapas. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GenerarJson_Click(object sender, EventArgs e) { OrderDto orderDto = new OrderDto(); try { orderDto.CancelOrder = Convert.ToBoolean(principalCancelOrder.Text.ToLower()); } catch (Exception exc) { MessageBox.Show(exc.Message); } CustomerDto customerDto = new CustomerDto(); customerDto.Apartment = customerApartment.Text; customerDto.BusinessAddress = customerBusinessAddress.Text; customerDto.BusinessName = customerBusinessName.Text; customerDto.City = customerCity.Text; customerDto.Comments = PrincipalComment.Text; try { customerDto.CustomerID = Convert.ToInt64(customerCustomerID.Text); } catch (Exception exc) { MessageBox.Show(exc.Message); } customerDto.Code = customerCode.Text; customerDto.DocumentNumber = customerDocumentNumber.Text; customerDto.DocumentType = customerDocumentType.Text; customerDto.Email = customerEmail.Text; customerDto.FirstName = customerFirstName.Text; customerDto.Floor = customerFloor.Text; customerDto.HouseNumber = customerHouseNumber.Text; customerDto.IVACategoryCode = customerIVACategoryCode.Text; customerDto.PayInternalTax = customerPayInternalTax.Checked; customerDto.LastName = customerLastName.Text; customerDto.MobilePhoneNumber = customerMobilePhoneNumber.Text; customerDto.PhoneNumber1 = customerPhoneNumber1.Text; customerDto.PhoneNumber2 = customerPhoneNumber2.Text; customerDto.PostalCode = customerPostalCode.Text; customerDto.ProvinceCode = customerProvinceCode.Text; customerDto.Street = customerStreet.Text; customerDto.User = customerUser.Text; orderDto.Customer = customerDto; try { orderDto.Date = Convert.ToDateTime(principalDate.Text); orderDto.PaidTotal = Convert.ToDecimal(principalPaidTotal.Text); orderDto.FinancialSurcharge = Convert.ToDecimal(principalFinancialSurcharge.Text); orderDto.WarehouseCode = Convert.ToString(principalWarehouseCode.Text); } catch (Exception exc) { MessageBox.Show(exc.Message); } orderDto.SellerCode = principalSellerCode.Text; orderDto.TransportCode = principalTransportCode.Text; orderDto.SaleConditionCode = int.TryParse(principalSaleConditionCode.Text, out int saleConditionCode) ? saleConditionCode : 0; orderDto.PriceListNumber = int.TryParse(principalPriceListNumber.Text, out int priceListNumber) ? priceListNumber : 0; orderDto.OrderID = principalOrderID.Text; orderDto.OrderItems = ListaOrderItems; orderDto.OrderNumber = principalOrderNumber.Text; orderDto.Payments = ListaPayments; orderDto.Comment = PrincipalComment.Text; orderDto.IvaIncluded = checkIvaIncluded.Checked; orderDto.InternalTaxIncluded = checkInternalTaxIncluded.Checked; orderDto.ValidateTotalWithPaidTotal = checkValidateTotalWithPaidTotal.Checked; CashPaymentDto cashPayment = new CashPaymentDto(); if (!string.IsNullOrEmpty(cashPaymentTotal.Text)) { try { cashPayment.PaymentTotal = Convert.ToDecimal(cashPaymentTotal.Text); cashPayment.PaymentID = Convert.ToInt64(cashPaymentId.Text); } catch (Exception exc) { MessageBox.Show(exc.Message); } cashPayment.PaymentMethod = cashPaymentMethod.Text; } ; if (checkGenerarCashPayment.Checked) { orderDto.CashPayment = cashPayment; } ShippingDto shipping = new ShippingDto(); shipping.Apartment = shippingApartment.Text; shipping.City = shippingCity.Text; shipping.DeliversMonday = shippingDeliversMonday.Text; shipping.DeliversTuesday = shippingDeliversTuesday.Text; shipping.DeliversWednesday = shippingDeliversWednesday.Text; shipping.DeliversThursday = shippingDeliversThursday.Text; shipping.DeliversFriday = shippingDeliversFriday.Text; shipping.DeliversSaturday = shippingDeliversSaturday.Text; shipping.DeliversSunday = shippingDeliversSunday.Text; shipping.DeliveryHours = shippingDeliveryHours.Text; shipping.Floor = shippingFloor.Text; shipping.HouseNumber = shippingHouseNumber.Text; shipping.PhoneNumber1 = shippingPhoneNumber1.Text; shipping.PhoneNumber2 = shippingPhoneNumber2.Text; shipping.PostalCode = shippingPostalCode.Text; shipping.ProvinceCode = shippingProvinceCode.Text; shipping.Street = shippingStreet.Text; shipping.ShippingCode = shippingShippingCode.Text; shipping.ShippingCost = 0; if (!String.IsNullOrWhiteSpace(shippingShippingCost.Text)) { shipping.ShippingCost = Convert.ToDecimal(shippingShippingCost.Text); } shipping.ShippingID = 0; if (!String.IsNullOrWhiteSpace(shippingShippingID.Text)) { shipping.ShippingID = Convert.ToInt64(shippingShippingID.Text); } if (checkGenerarShipping.Checked) { orderDto.Shipping = shipping; } try { orderDto.Total = Convert.ToDecimal(principalTotal.Text); orderDto.TotalDiscount = Convert.ToDecimal(principalTotalDiscount.Text); } catch (Exception exc) { MessageBox.Show(exc.Message); } string json = JsonConvert.SerializeObject(orderDto, Formatting.Indented); resultadoSerializado.Text = json; tabControl1.SelectTab("tabResultado"); }