// GET: InvoiceForPurchases/Edit/5 public ActionResult Edit(int id) { InvoiceForPurchase item = InvoiceForPurchaseMethods.GetItem(id); if (item == null) { return(HttpNotFound()); } return(View(item)); }
/// <summary> /// Общая стоимость /// </summary> /// <param name="sales">Накладная</param> /// <returns>Общая стоимость</returns> public static decimal TotalPrice(InvoiceForPurchase sales) { decimal price = 0; foreach (var item in sales.Products) { price = price + item.Price; } return(price); }
public ActionResult Edit(InvoiceForPurchase item) { try { if (ModelState.IsValid) { InvoiceForPurchaseMethods.ChangeItem(item); return(RedirectToAction("Index")); } } catch (DataException) { //Log the error (add a variable name after DataException) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(item)); }
/// <summary> /// Конвертация в продукт /// </summary> /// <param name="client">Продукт БД</param> /// <returns>Продукт</returns> public static Product Convert(ProductEnt product, bool logic = true) { if (product != null) { SalesInvoice sales = null; InvoiceForPurchase invoiceForPurchase = null; Category category = null; if (logic == true) { //sales = Convert(product.SalesInvoice, false); category = Convert(product.Category, false); invoiceForPurchase = Convert(product.InvoiceForPurchase, false); } Product productEnt = new Product { Description = product.Description, //SalesInvoice = sales, //SalesInvoiceId=product.SalesInvoiceId, InvoiceForPurchase = invoiceForPurchase, Commit = product.Commit, InvoiceForPurchaseId = product.InvoiceForPurchaseId, CategoryId = product.CategoryId, CostPrice = product.CostPrice, DateOfPurchase = product.DateOfPurchase, DateOfSale = product.DateOfSale, Id = product.Id, Name = product.Name, Archiving = product.Archiving, Category = category, /*new { Name = product.Category.Name },*/ Price = product.Price, Status = product.Status }; return(productEnt); } else { return(null); } }
/// <summary> /// Конвертация в накладную закупок /// </summary> /// <param name="client">Накладная закупок БД</param> /// <returns>Накладная закупок</returns> public static InvoiceForPurchase Convert(InvoiceForPurchaseEnt invoiceForPurchase, bool logic = true) { if (invoiceForPurchase != null) { List <Product> productEnts = null; Employee employee = null; CompanyProvider companyProvider = null; if (logic == true) { companyProvider = Convert(invoiceForPurchase.CompanyProvider, false); employee = Convert(invoiceForPurchase.Employee, false); productEnts = new List <Product>(); foreach (var item in invoiceForPurchase.ProductEnts) { productEnts.Add(Convert(item, false)); } } InvoiceForPurchase invoiceForPurchaseEnt = new InvoiceForPurchase { Date = invoiceForPurchase.Date, Description = invoiceForPurchase.Description, CompanyProviderId = invoiceForPurchase.CompanyProviderId, EmployeeId = invoiceForPurchase.EmployeeId, Employee = employee, Id = invoiceForPurchase.Id, CompanyProvider = companyProvider, Archiving = invoiceForPurchase.Archiving, Products = productEnts }; return(invoiceForPurchaseEnt); } else { return(null); } }
/// <summary> /// Конвертация в накладную закупок БД /// </summary> /// <param name="client">Накладная закупок</param> /// <returns>Накладная закупок БД</returns> public static InvoiceForPurchaseEnt Convert(InvoiceForPurchase invoiceForPurchase) { if (invoiceForPurchase != null) { var x = Unit.InvoiceForPurchaseRepository.GetItem(invoiceForPurchase.Id); if (x != null) { return(x); } else { List <ProductEnt> productEnts = new List <ProductEnt>(); foreach (var item in invoiceForPurchase.Products) { productEnts.Add(Convert(item)); } InvoiceForPurchaseEnt invoiceForPurchaseEnt = new InvoiceForPurchaseEnt { CompanyProvider = Convert(invoiceForPurchase.CompanyProvider), Date = invoiceForPurchase.Date, Description = invoiceForPurchase.Description, Employee = Convert(invoiceForPurchase.Employee), Id = invoiceForPurchase.Id, CompanyProviderId = invoiceForPurchase.CompanyProviderId, EmployeeId = invoiceForPurchase.EmployeeId, ProductEnts = productEnts, Archiving = invoiceForPurchase.Archiving }; return(invoiceForPurchaseEnt); } } else { return(null); } }
/// <summary> /// Поиск элемента /// </summary> /// <param name="item">Элемент</param> /// <returns>Логическое значение</returns> static public bool ChangeItem(InvoiceForPurchase item) { return(Unit.InvoiceForPurchaseRepository.ChangeItem(ConvertEntity.Convert(item))); }