public PurchesInfo PurchesAccount() { PurchesInfo purches = new PurchesInfo(); purches.PurchesPrice = _context.PurchesInfos.Sum(a => a.PurchesPrice); return(purches); }
public JsonResult Add([FromBody] PurchesViewModel purches) { if (ModelState.IsValid) { try { Product product = new Product { ProductName = purches.ProductName, ProductQuentity = purches.ProductQuentity, ProductPurchesPrice = purches.ProductPurchesPrice, ProductSalePrice = purches.ProductSalePrice, IsStoed = purches.IsStoed, }; if (_services.GetProductByName(purches.ProductName) == null) { _services.SetProduct(product); } else { _services.UpdateProductForPurches(product); } PurchesInfo purchesInfo = new PurchesInfo { PurchesPersonName = purches.PurchesPersonName, PurchesPersonPhoneNumber = purches.PurchesPersonPhoneNumber, PurchesPersonEmail = purches.PurchesPersonEmail, PurchesDate = DateTime.Now, PurchesPrice = purches.PurchesPrice, PurchesOnCash = purches.PurchesOnCash, PurchesOnDebt = purches.PurchesOnDebt, ProductId = (_services.GetProductByName(purches.ProductName)).ProductId, PurchesQuentity = purches.ProductQuentity }; _services.SetPurchesInfo(purchesInfo); result.IsSuccess = true; result.Message = "Purches successfully complete"; } catch (Exception ex) { result.IsSuccess = false; result.Message = ex.Message; } } return(Json(result)); }
public void SetPurchesInfo(PurchesInfo purchesInfo) { _context.Add(purchesInfo); _context.SaveChanges(); }