public ActionResult ChemPurcReq(PrqChemPurcReq modelReq) { _vmMsg = modelReq != null && modelReq.RequisitionID == 0 ? _objChemPurcReq.SaveData(modelReq, Convert.ToInt32(Session["UserID"]), "ChemPurcReq/ChemPurcReq") : _objChemPurcReq.UpdateData(modelReq, Convert.ToInt32(Session["UserID"])); return(Json(new { msg = _vmMsg }, JsonRequestBehavior.AllowGet)); }
public ValidationMsg ApprovedData(PrqChemPurcReq model, int userId) { try { var prqChemPurcReq = _unit.PrqChemPurcReqRepository.GetByID(model.RequisitionID); prqChemPurcReq.ApprovedBy = userId; prqChemPurcReq.ApproveDate = DateTime.Now; prqChemPurcReq.RecordStatus = "APV"; prqChemPurcReq.ApprovalAdvice = model.ApprovalAdvice; prqChemPurcReq.ApprovalAdviceNote = model.ApprovalAdviceNote; _unit.PrqChemPurcReqRepository.Update(prqChemPurcReq); if (model.ChemPurcReqItems.Count != 0) { foreach (var items in model.ChemPurcReqItems) { var objItem = _unit.PrqChemPurcReqItemRepository.GetByID(items.RequisitionItemID); objItem.PackSize = items.SizeID; objItem.PackQty = items.PackQty; objItem.ApproveQty = Convert.ToDecimal(items.ApproveQty); objItem.ApprovalState = ReturnApprovalStateToShort(items.ApprovalState); _unit.PrqChemPurcReqItemRepository.Update(objItem); } } if (_unit.IsSaved()) { _vmMsg.Type = Enums.MessageType.Success; _vmMsg.Msg = "Approved Successfully."; } else { _vmMsg.Type = Enums.MessageType.Error; _vmMsg.Msg = "Approval Failed."; } } catch (Exception) { _vmMsg.Type = Enums.MessageType.Error; _vmMsg.Msg = "Approval Failed."; } return(_vmMsg); }
public ValidationMsg UpdateData(PrqChemPurcReq modelReq, int userId) { try { using (var tx = new TransactionScope()) { using (_context) { var objModel = _context.PRQ_ChemPurcReq.FirstOrDefault(r => r.RequisitionID == modelReq.RequisitionID); if (objModel != null) { objModel.RequisitionCategory = modelReq.RequisitionCategory; objModel.RequisitionType = modelReq.RequisitionType; objModel.RequisitionFrom = modelReq.RequisitionFrom; objModel.RequisitionTo = modelReq.RequisitionTo; objModel.RequiredByTime = modelReq.RequiredByTime; objModel.ReqRaisedOn = DalCommon.SetDate(modelReq.ReqRaisedOn); objModel.ReqRaisedBy = modelReq.ReqRaisedBy; objModel.ModifiedBy = userId; objModel.ModifiedOn = DateTime.Now; } _context.SaveChanges(); if (modelReq.ChemPurcReqItems != null) { foreach (var chemItem in modelReq.ChemPurcReqItems) { if (chemItem.RequisitionItemID == 0) { var objItem = new PRQ_ChemPurcReqItem(); objItem.RequisitionID = modelReq.RequisitionID; objItem.ItemID = chemItem.ItemID; objItem.PackSize = chemItem.SizeID; objItem.SizeUnit = chemItem.PackUnitID; objItem.PackQty = chemItem.PackQty; objItem.RequsitionQty = chemItem.RequisitionQty; objItem.RequisitionUnit = chemItem.RequisitionUnit; objItem.ManufacturerID = chemItem.ManufacturerID; objItem.SupplierID = modelReq.RequisitionTo; objItem.SetOn = DateTime.Now; objItem.SetBy = userId; _context.PRQ_ChemPurcReqItem.Add(objItem); } else { var updateItem = _context.PRQ_ChemPurcReqItem.First(r => r.RequisitionItemID == chemItem.RequisitionItemID); updateItem.ItemID = chemItem.ItemID; updateItem.PackSize = chemItem.SizeID; updateItem.SizeUnit = chemItem.PackUnitID; updateItem.PackQty = chemItem.PackQty; updateItem.RequsitionQty = chemItem.RequisitionQty; updateItem.RequisitionUnit = chemItem.RequisitionUnit; updateItem.SupplierID = modelReq.RequisitionTo; updateItem.ManufacturerID = chemItem.ManufacturerID; updateItem.ModifiedOn = DateTime.Now; updateItem.ModifiedBy = userId; } } _context.SaveChanges(); } } tx.Complete(); _vmMsg.Type = Enums.MessageType.Success; _vmMsg.Msg = "Updated Successfully."; _vmMsg.ReturnId = modelReq.RequisitionID; _vmMsg.ReturnCode = modelReq.RequisitionNo; } } catch (Exception) { _vmMsg.Type = Enums.MessageType.Error; _vmMsg.Msg = "Failed to save."; } return(_vmMsg); }
public ValidationMsg SaveData(PrqChemPurcReq modelReq, int userId, string pageUrl) { try { using (var tx = new TransactionScope()) { var currentRequisitionId = 0; var currentRequisitionCode = DalCommon.GetPreDefineNextCodeByUrl(pageUrl); //var currentRequisitionCode = DalCommon.GetPreDefineValue("1", "00051"); using (_context) { var chemPurcReq = new PRQ_ChemPurcReq { RequisitionNo = currentRequisitionCode, RequisitionCategory = modelReq.RequisitionCategory, RequisitionType = modelReq.RequisitionType, ReqRaisedOn = DalCommon.SetDate(modelReq.ReqRaisedOn), RequisitionFrom = modelReq.RequisitionFrom, RequisitionTo = modelReq.RequisitionTo, RequiredByTime = modelReq.RequiredByTime, ReqRaisedBy = modelReq.ReqRaisedBy, RecordStatus = "NCF", RequisitionState = "RNG", SetOn = DateTime.Now, SetBy = userId, IPAddress = GetIPAddress.LocalIPAddress() }; _context.PRQ_ChemPurcReq.Add(chemPurcReq); _context.SaveChanges(); currentRequisitionId = chemPurcReq.RequisitionID; if (modelReq.ChemPurcReqItems != null) { foreach (var chemItem in modelReq.ChemPurcReqItems.Select(item => new PRQ_ChemPurcReqItem() { RequisitionID = currentRequisitionId, ItemID = item.ItemID, SupplierID = modelReq.RequisitionTo, PackSize = item.SizeID, SizeUnit = item.PackUnitID, PackQty = item.PackQty, RequsitionQty = item.RequisitionQty, RequisitionUnit = item.RequisitionUnit, ManufacturerID = item.ManufacturerID, SetOn = DateTime.Now, SetBy = userId })) { _context.PRQ_ChemPurcReqItem.Add(chemItem); _context.SaveChanges(); } } } tx.Complete(); _vmMsg.Type = Enums.MessageType.Success; _vmMsg.Msg = "Saved Successfully."; _vmMsg.ReturnId = currentRequisitionId; _vmMsg.ReturnCode = currentRequisitionCode; } } catch (Exception) { _vmMsg.Type = Enums.MessageType.Error; _vmMsg.Msg = "Failed to save."; } return(_vmMsg); }
public ActionResult ApprovedData(PrqChemPurcReq model) { _vmMsg = _objChemPurcReq.ApprovedData(model, Convert.ToInt32(Session["UserID"])); return(Json(new { msg = _vmMsg }, JsonRequestBehavior.AllowGet)); }