public bool Insert(WAMS_REQUISITION_MASTER entity, List <WAMS_REQUISITION_DETAILS> entityDetails) { _repository.Add(entity); _unitOfWork.CommitChanges(); foreach (var detail in entityDetails) { var detailEntity = new WAMS_REQUISITION_DETAILS { vMRF = entity.Id, vStockID = detail.vStockID, fQuantity = detail.fQuantity, fTobePurchased = detail.fTobePurchased, Remark = detail.Remark, iFollowUpRequired = 1, iPurchased = 0, iSent = 0, vStatus = "Open", iEnable = true, dDateAssign = entity.dCreated, dCreated = entity.dCreated, iCreated = entity.iCreated }; _repositoryDetail.Add(detailEntity); } _unitOfWork.CommitChanges(); return(true); }
public ActionResult Create(int?id) { var userName = System.Web.HttpContext.Current.User.Identity.Name; var user = _systemService.GetUserAndRole(0, userName); if (user == null) { return(RedirectToAction("Index", "Login")); } if (user.RequisitionR == 0) { return(RedirectToAction("Index", "Home")); } var item = new WAMS_REQUISITION_MASTER(); if (id.HasValue) { item = _service.GetByKey(id.Value); } else { item.vMRF = (Convert.ToInt32(_service.GetCodeLastest()) + 1).ToString(CultureInfo.InvariantCulture); } var model = new RequisitionViewModel { Id = item.Id, vMRF = item.vMRF, vFrom = item.vFrom, iStore = item.iStore, vDeliverLocation = item.vDeliverLocation, vProjectID = item.vProjectID, Timestamp = item.Timestamp, UserLogin = user, Stores = new SelectList(_systemService.StoreList(), "Id", "Name"), Projects = new SelectList(_systemService.ProjectList(), "Id", "vProjectID"), ProjectNames = new SelectList(_systemService.ProjectList(), "Id", "vProjectName") }; if (id.HasValue) { var temp = _service.ListConditionDetail(id.Value, "1"); model.GetRequisitionDetailsVResults = temp; model.TotalRecords = temp.Count; } if (item.dDeliverDate.HasValue) { model.DeliverDateTemp = item.dDeliverDate.Value.ToString("dd/MM/yyyy"); } return(View(model)); }
public bool Update(WAMS_REQUISITION_MASTER entity, List <WAMS_REQUISITION_DETAILS> entityDetails, string LstDeleteDetailItem) { _repository.Update(entity); foreach (var detail in entityDetails) { if (detail.ID != 0) { var detailEntity = _repositoryDetail.GetByKey(detail.ID); detailEntity.vStockID = detail.vStockID; detailEntity.fQuantity = detail.fQuantity; detailEntity.fTobePurchased = detail.fTobePurchased; detailEntity.Remark = detail.Remark; detailEntity.dModified = DateTime.Now; detailEntity.iModified = entity.iModified; _repositoryDetail.Update(detailEntity); } else { var detailEntity = new WAMS_REQUISITION_DETAILS { vMRF = entity.Id, vStockID = detail.vStockID, fQuantity = detail.fQuantity, fTobePurchased = detail.fTobePurchased, Remark = detail.Remark, iFollowUpRequired = 1, iPurchased = 0, iSent = 0, vStatus = "Open", iEnable = true, dDateAssign = entity.dCreated, dCreated = entity.dCreated, iCreated = entity.iCreated }; _repositoryDetail.Add(detailEntity); } } if (!string.IsNullOrEmpty(LstDeleteDetailItem)) { var listStrLineElements = LstDeleteDetailItem.Split(';').ToList(); foreach (var itemDetail in listStrLineElements) { _customRepository.DeleteDetail(Convert.ToInt32(itemDetail)); } } _unitOfWork.CommitChanges(); return(true); }