public ActionResult ProductEditRows(Product editedItem) { // Get the grid and database models var gridModel = new SkladJqGridModel(); var datacontextModel = new SkladDataContext(); // If we are in "Edit" mode if (gridModel.WarehouseGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow) { // Get the data from and find the item corresponding to the edited row Product item = (from x in datacontextModel.Products where x.ProductId == editedItem.ProductId select x).First <Product>(); // update the item information UpdateProduct(item, editedItem); datacontextModel.SaveChanges(); } if (gridModel.WarehouseGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow) { Product item = (from x in datacontextModel.Products where x.ProductId == editedItem.ProductId select x) .First <Product>(); // delete the record datacontextModel.Products.Remove(item); datacontextModel.SaveChanges(); } return(RedirectToAction("Product", "Reference")); }
public int GetDocumentNumber(SkladDataContext context, int year, int documentTypeId) { int documentNumber = 1; // lock to all rows var transactionOptions = new TransactionOptions { IsolationLevel = IsolationLevel.RepeatableRead, Timeout = TimeSpan.MaxValue }; using (var scope = new TransactionScope(TransactionScopeOption.Required, transactionOptions)) { var item = context.DocumentCounters.Where(x => x.DocumentTypeId == documentTypeId && x.Year == year).FirstOrDefault(); if (item == null) { context.DocumentCounters.Add(new DocumentCounter { Counter = documentNumber, Year = year, DocumentTypeId = documentTypeId }); } else { item.Counter = item.Counter + 1; documentNumber = item.Counter; } context.SaveChanges(); scope.Complete(); } return(documentNumber); }
public void AddNewProduct(int contractorId, string article, decimal purchaseprice, decimal saleprice, decimal vat) { if (contractorId <= 0 || String.IsNullOrEmpty(article)) { return; } Product item = new Product() { Article = article, PurchasePrice = purchaseprice, SalePrice = saleprice, VAT = vat, ContractorId = contractorId }; var datacontextModel = new SkladDataContext(); PrepareProductData(item); item.Supplier = (from x in datacontextModel.Contractors where x.ContractorId == item.ContractorId && x.ContractorTypeId == (int)EntityEnum.ContractorTypeEnum.Factory select x).First <Contractor>(); if (item.Supplier == null) { logger.ErrorFormat("для товара {0} не найден поставщик с id={1}", item.Article, item.ContractorId); return; } string validationMessage = ValidateProductData(datacontextModel.Products, item, true); if (!String.IsNullOrEmpty(validationMessage)) { logger.Error(validationMessage); return; } datacontextModel.Products.Add(item); datacontextModel.SaveChanges(); logger.InfoFormat("Создан товар {0} от поставщика {1}", item.Article, item.Supplier.Code); }
public void DeleteDocument(SkladDataContext context, Document document) { // При удалении возврата - обновить поле Shipment в родителе if (document.DocumentTypeId == (int)SidBy.Sklad.Domain.Enums.EntityEnum.DocumentTypeEnum.Refunds) { foreach (var product in document.Products) { var productLineToUpdate = context.ProductLines.Where(x => x.ProductId == product.ProductId).FirstOrDefault(); if (productLineToUpdate != null) { productLineToUpdate.Shipped = productLineToUpdate.Shipped - product.Quantity; if (productLineToUpdate.Shipped < 0) { productLineToUpdate.Shipped = 0; } } } context.SaveChanges(); } }
public ActionResult ContractorEditRows(Contractor editedItem) { // Get the grid and database models var gridModel = new SkladJqGridModel(); var datacontextModel = new SkladDataContext(); // If we are in "Edit" mode if (gridModel.ContractorGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow) { PrepareContractorData(editedItem); string validationMessage = ValidateContractorData(datacontextModel.Contractors, editedItem, false); if (!String.IsNullOrEmpty(validationMessage)) { return(gridModel.ContractorGrid.ShowEditValidationMessage(validationMessage)); } // Get the data from and find the item corresponding to the edited row Contractor item = (from x in datacontextModel.Contractors where x.ContractorId == editedItem.ContractorId select x).First <Contractor>(); // update the item information UpdateContractor(item, editedItem); datacontextModel.SaveChanges(); logger.InfoFormat("контрагент изменён {0}", item.Code); } if (gridModel.ContractorGrid.AjaxCallBackMode == AjaxCallBackMode.AddRow) { PrepareContractorData(editedItem); string validationMessage = ValidateContractorData(datacontextModel.Contractors, editedItem, true); if (!String.IsNullOrEmpty(validationMessage)) { return(gridModel.ContractorGrid.ShowEditValidationMessage(validationMessage)); } // since we are adding a new item, create a new istance Contractor item = new Contractor() { IsArchived = false, CreatedAt = DateTime.Now }; // set the new item information UpdateContractor(item, editedItem); datacontextModel.Contractors.Add(item); datacontextModel.SaveChanges(); logger.InfoFormat("контрагент добавлен {0}", item.Code); } if (gridModel.ContractorGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow) { Contractor item = (from x in datacontextModel.Contractors where x.ContractorId == editedItem.ContractorId select x) .First <Contractor>(); // delete the record datacontextModel.Contractors.Remove(item); datacontextModel.SaveChanges(); logger.InfoFormat("контрагент удалён {0}", item.Code); } return(RedirectToAction("Contractor", "Reference")); }