public GeneralResponse AddProductLog(AddProductLogRequestOld request) { GeneralResponse response = new GeneralResponse(); try { ProductLog productLog = new ProductLog(); productLog.ID = Guid.NewGuid(); productLog.CreateDate = PersianDateTime.Now; productLog.CreateEmployee = _employeeRepository.FindBy(request.CreateEmployeeID); productLog.Note = request.Note; productLog.Closed = request.Closed; productLog.InputSerialNumber = request.InputSerialNumber; productLog.LogDate = request.LogDate; productLog.Product = this._productRepository.FindBy(request.ProductID); productLog.ProductSerialFrom = request.ProductSerialFrom; productLog.ProductSerialTo = request.ProductSerialTo; productLog.PurchaseBillNumber = request.PurchaseBillNumber; productLog.PurchaseDate = request.PurchaseDate; productLog.PurchaseUnitPrice = request.PurchaseUnitPrice; productLog.SellerName = request.SellerName; productLog.UnitsIO = request.UnitsIO; productLog.RowVersion = 1; #region Validation if (productLog.GetBrokenRules().Count() > 0) { foreach (BusinessRule businessRule in productLog.GetBrokenRules()) { response.ErrorMessages.Add(businessRule.Rule); } return(response); } #endregion Product product = productLog.Product; product.UnitsInStock += productLog.UnitsIO; _productRepository.Save(product); _productLogRepository.Add(productLog); _uow.Commit(); } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); } return(response); }
public ActionResult Create(ProductLogDetailView productLogDetailView) { productLogDetailView.EmployeeView = GetEmployee(); GetRequest getCenterRequest = new GetRequest() { ID = productLogDetailView.ProductLogView.ProductID }; productLogDetailView.ProductLogView.ProductName = _productService.GetProduct(getCenterRequest).ProductView.ProductName; if (ModelState.IsValid) { try { AddProductLogRequestOld request = new AddProductLogRequestOld(); request.CreateEmployeeID = GetEmployee().ID; request.Closed = productLogDetailView.ProductLogView.Closed; request.InputSerialNumber = productLogDetailView.ProductLogView.InputSerialNumber; request.LogDate = productLogDetailView.ProductLogView.LogDate; request.Note = productLogDetailView.ProductLogView.Note; request.ProductID = productLogDetailView.ProductLogView.ProductID; request.ProductSerialFrom = productLogDetailView.ProductLogView.ProductSerialFrom; request.ProductSerialTo = productLogDetailView.ProductLogView.ProductSerialTo; request.PurchaseBillNumber = productLogDetailView.ProductLogView.PurchaseBillNumber; request.PurchaseDate = productLogDetailView.ProductLogView.PurchaseDate; request.PurchaseUnitPrice = productLogDetailView.ProductLogView.PurchaseUnitPrice; request.SellerName = productLogDetailView.ProductLogView.SellerName; if (productLogDetailView.ProductLogView.IOTypeForCreate == "O") { request.UnitsIO = -Math.Abs(productLogDetailView.ProductLogView.UnitsIO); } else { request.UnitsIO = Math.Abs(productLogDetailView.ProductLogView.UnitsIO); } GeneralResponse response = this._productLogService.AddProductLog(request); if (response.success) { return(RedirectToAction("Index/" + request.ProductID)); } else { foreach (string error in response.ErrorMessages) { ModelState.AddModelError("", error); } return(View(productLogDetailView)); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View(productLogDetailView)); } } return(View(productLogDetailView)); }