public void SaveSaleValidation(SaleInput sale) { if (sale == null) { throw new ValidationResponseException("Ocorreu um erro ao enviar os dados pro Servidor!"); } if (sale.InvalidAddress()) { throw new ValidationResponseException("Ajuste seus dados de endereço"); } var products = BlProductsList.GetProducts(new FiltersProducts { Ids = sale.ProductsId }); if (products?.Any(x => x.UserId == sale.UserId) ?? false) { throw new ValidationResponseException("Você não pode comprar os seus próprios produtos"); } var invalidStatus = new List <ProductStatus> { ProductStatus.Invalid, ProductStatus.Sold }; if (products?.Any(x => invalidStatus.Contains(x.Status)) ?? false) { throw new ValidationResponseException($"Os produtos {string.Join(", ", products.Where(x => invalidStatus.Contains(x.Status)).Select(x => x.Name))} se encontram inválidos para venda"); } }
public async Task InsertAsync(SaleInput input) { var itens = new List <Item>(); var total = 0.00M; if (input.Itens.Count <= 0) { throw new Exception("Para a venda, é necessário pelo menos informar um item"); } foreach (var itemId in input.Itens) { var item = await _itemRepository .GetByIdAsync(itemId) .ConfigureAwait(false); var stock = await _stockGateway .PutAsync(urlStock, itemId) .ConfigureAwait(false); if (!stock.Success) { throw new Exception(stock.ErrorMessage); } itens.Add(item); total += item.Price; } var payment = new PaymentInput() { CardNumber = input.Payment.CardNumber, SubDivision = input.Payment.SubDivision, Total = total }; var response = await _paymentGateway .PostAsync(urlPayment, payment) .ConfigureAwait(false); if (!response.Success) { throw new Exception(response.ErrorMessage); } var sale = new Sale(new Payment(response.ReadToObject.Id, response.ReadToObject.CardNumber, response.ReadToObject.SubDivision, response.ReadToObject.Total, response.ReadToObject.TotalSubDivision)); sale.AddItems(itens); await _saleRepository .InsertAsync(sale) .ConfigureAwait(false); }
public void Create(SaleInput input) { SaveSaleValidation(input); var sale = Save(new Sale { Destination = input.Destination, UserId = input.UserId, Total = GetSaleTotal(input.ProductsId) }); BlSaleProducts.SaveProducts(new SaveSaleProductsInput { SaleId = sale.Id, ProductsId = input.ProductsId }); }
public void AddSales(SalesOrder order, SaleInput saleInput) //新建客户订单(新建订单应通过BookDao生成,该函数应用于旧数据导入等功能中) { object geted = CheckType(order);//机型比对 获取比对结果 if (geted == null) { MessageBox.Show("未知型号,请前往库存管理核对", "错误提示", MessageBoxButton.OK); } else { try { SQLiteConnection con = new SQLiteConnection(@"Data Source=SQL\GREE.db"); con.Open(); string sql = "INSERT INTO main.SalesOrder " + "(totalNumber,subunitNumber,orderDate,customerName,customerTel," + "customerAddress,machineTypeClass,machineTypeName,machineNumber," + "quantity,sellingPrice,totalPrice,salesman," + "earnestMoney,paymentMethod," + "Remarks,state)VALUES(" + "\'" + order.TNVal + "\'" + "," + "\'" + order.SNVal + "\'" + "," + "\'" + order.OrderDateVal + "\'" + "," + "\'" + order.CNameVal + "\'" + "," + "\'" + order.CTelVal + "\'" + "," + "\'" + order.CAddressVal + "\'" + "," + "\'" + order.MTClassVal + "\'" + "," + "\'" + order.MTNameVal + "\'" + "," + "\'" + order.MTNumberVal + "\'" + "," + "\'" + order.QuantityVal + "\'" + "," + "\'" + order.SellingPriceVal + "\'" + "," + "\'" + order.TotalPriceVal + "\'" + "," + "\'" + order.SalesmanVal + "\'" + "," + "\'" + order.EarnestMoneyVal + "\'" + "," + "\'" + order.PaymentMethodVal + "\'" + "," + "\'" + order.RemarksVal + "\'" + "," + "'未完成'" + ");"; SQLiteCommand command = new SQLiteCommand(sql, con); command.ExecuteNonQuery(); command.Dispose(); con.Close(); func.MessageBox_SaleInput(saleInput, true); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public async Task <IActionResult> Post([FromBody] SaleInput input) { var transaction = Agent.Tracer.StartTransaction("Criando uma venda!", "Requisição"); try { await _saleAppService.InsertAsync(input); return(Created("", "")); } catch (Exception ex) { transaction.CaptureException(ex); return(BadRequest($"Erro => {ex.Message}")); } finally { transaction.End(); } }
public IActionResult Create([FromBody] SaleInput input) { _blSales.Create(input); return(Ok()); }
//SaleInput public void MessageBox_SaleInput(SaleInput sale, bool state) { sale.message.IsActive = state; }