public bool UpdateOrderRequestItem(Model.OrderRequestItem entity) { using (var context = new SCMSEntities()) { var existing = context.OrderRequestItems.FirstOrDefault(o => o.Id == entity.Id); context.Entry(existing).CurrentValues.SetValues(entity); return((context.SaveChanges() > 0) ? true : false); } }
public ActionResult EditItemInEditMode(Guid id) { Model.OrderRequestItem model = orderRequestService.GetOrderRequestItemById(id); List <BudgetLineView> blList = orderRequestService.GetProjectBugdetLines((Guid)model.ProjectBudget.BudgetCategory.ProjectDonorId); model.BudgetLines = new SelectList(blList, "Id", "Description", model.ProjectBudget.Id); model.Items = new SelectList(orderRequestService.GetItems(), "Id", "Name"); ViewBag.Action = Resources.Global_String_Update; return(View("AddItemInEditMode", model)); }
public void DeleteOrderRequestItem(Guid id) { using (var dbContext = new SCMSEntities()) { Model.OrderRequestItem orItem = dbContext.OrderRequestItems.SingleOrDefault(c => c.Id.Equals(id)); var or = dbContext.OrderRequests.SingleOrDefault(o => o.Id == orItem.OrderRequestId); or.TotalAmount -= orItem.EstimatedPrice; dbContext.OrderRequestItems.Remove(orItem); dbContext.SaveChanges(); ClearPPItemSessionData(); ClearORSessionData(); } }
public ActionResult SaveRequestItem(Guid orItemId, Model.OrderRequestItem entity) { if (!orderRequestService.ItemAlreadyAddedToOR(entity.ItemId, entity.OrderRequestId) || !orItemId.Equals(Guid.Empty)) { entity.Id = orItemId; if (orderRequestService.AddOrderRequstItem(entity, UserSession.CurrentSession.NewOR)) { ViewBag.Response = 1; ViewBag.msg = Resources.OrderRequestController_String_ORItemSaved; } ModelState.Clear(); } else { ViewBag.Response = 0; ViewBag.msg = Resources.OrderRequestController_String_ItemAlreadyAdded; } return(ViewOrderRequestItems(entity.OrderRequestId)); }
public bool AddOrderRequstItem(Model.OrderRequestItem entity, Model.OrderRequest ORentity) { using (var context = new SCMSEntities()) { using (TransactionScope scope = new TransactionScope()) { try { var orderRequest = context.OrderRequests.FirstOrDefault(o => o.Id == entity.OrderRequestId); if (ORentity != null && orderRequest == null) { ORentity.TotalAmount = entity.EstimatedPrice; context.OrderRequests.Add(ORentity); entity.Id = Guid.NewGuid(); context.OrderRequestItems.Add(entity); if ((context.SaveChanges() > 0)) { scope.Complete(); } else { scope.Dispose(); return(false); } } else { if (entity.Id.Equals(Guid.Empty)) { entity.Id = Guid.NewGuid(); context.OrderRequestItems.Add(entity); if ((context.SaveChanges() > 0)) { orderRequest.TotalAmount += entity.EstimatedPrice; if ((context.SaveChanges() > 0)) { scope.Complete(); } else { scope.Dispose(); return(false); } } else { scope.Dispose(); return(false); } } else { var orItem = context.OrderRequestItems.FirstOrDefault(p => p.Id == entity.Id); orderRequest.TotalAmount -= orItem.EstimatedPrice; orderRequest.TotalAmount += entity.EstimatedPrice; orItem.BudgetLineId = entity.BudgetLineId; orItem.EstimatedPrice = entity.EstimatedPrice; orItem.EstimatedUnitPrice = entity.EstimatedUnitPrice; orItem.ItemDescription = entity.ItemDescription; orItem.ItemId = entity.ItemId; orItem.Quantity = entity.Quantity; orItem.Remarks = entity.Remarks; if ((context.SaveChanges() > 0)) { scope.Complete(); } else { scope.Dispose(); return(false); } } } } catch (Exception ex) { scope.Dispose(); throw new Exception(ex.Message); } } if (entity.ProcurementPlanItemId != null) { ClearPPSessionData(); ClearPPItemSessionData(); } ClearORSessionData(); return(true); } }
private void ConvertORItemNumbersToPOCurrency(Model.PurchaseOrder po, Model.OrderRequestItem orItem) { orItem.EstimatedUnitPrice = Math.Round((decimal)exchangeRateService.GetForeignCurrencyValue(po.Currency, orItem.OrderRequest.Currency, orItem.EstimatedUnitPrice, countryProg.Id), 2); orItem.EstimatedPrice = orItem.EstimatedUnitPrice * orItem.Quantity; }