// To Update Outstanding Requisition public static OutstandingReqModel UpdateOutReq (OutstandingReqModel ordm, out string error) { LUSSISEntities entities = new LUSSISEntities(); error = ""; OutstandingReqModel outreqm = new OutstandingReqModel(); outstandingrequisition outreq = new outstandingrequisition(); try { // finding the db object using API model outreq = entities.outstandingrequisitions .Where(x => x.outreqid == ordm.OutReqId) .FirstOrDefault(); // transfering data from API model to DB Model outreq.reqid = ordm.ReqId; outreq.reason = ordm.Reason; var TempStatus = outreq.status; outreq.status = ordm.Status; // saving the update entities.SaveChanges(); if (TempStatus != ordm.Status && ordm.Status == ConOutstandingsRequisition.Status.DELIVERED) { foreach (outstandingrequisitiondetail outrd in outreq.outstandingrequisitiondetails) { InventoryModel invm = InventoryRepo.GetInventoryByItemid(outrd.itemid, out error); invm.Stock -= outrd.qty; invm = InventoryRepo.UpdateInventory(invm, out error); InventoryTransactionModel invtm = new InventoryTransactionModel(); invtm.ItemID = outrd.itemid; invtm.InvID = invm.Invid; invtm.Qty = (outrd.qty) * -1; invtm.TransDate = DateTime.Now; invtm.Remark = "Fulfill Outstanding" + outrd.outreqid; invtm.TransType = ConInventoryTransaction.TransType.OUTSTANDING; invtm = InventoryTransactionRepo.CreateInventoryTransaction(invtm, out error); } } // return the updated model outreqm = ConvertDBOutReqToAPIOutReq(outreq); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(outreqm); }
//Update Adjustment public static AdjustmentModel UpdateAdjustment(AdjustmentModel adjm, out string error) { error = ""; LUSSISEntities entities = new LUSSISEntities(); NotificationModel nom = new NotificationModel(); adjustment adj = new adjustment(); try { adj = entities.adjustments.Where(a => a.adjid == adjm.Adjid).First <adjustment>(); adj.raisedby = adjm.Raisedby; adj.raisedto = adjm.Raisedto; adj.issueddate = adjm.Issueddate; adj.status = adjm.Status; nom.Remark = "The Adjustment Voucher has been Rejected!"; if (adj.status == ConAdjustment.Active.APPROVED) { nom.Remark = "The Adjustment Voucher has been Approved!"; } List <AdjustmentDetailModel> adjustds = AdjustmentDetailRepo.GetAdjustmentDetailByAdjID(adj.adjid, out error); foreach (AdjustmentDetailModel adjustd in adjustds) { InventoryModel inventm = InventoryRepo.GetInventoryByItemid(adjustd.Itemid, out error); inventory invent = entities.inventories.Where(i => i.invid == inventm.Invid).First <inventory>(); invent.stock += adjustd.Adjustedqty; InventoryTransactionModel invtm = new InventoryTransactionModel(); invtm.InvID = invent.invid; invtm.ItemID = invent.itemid; invtm.Qty = adjustd.Adjustedqty; invtm.TransType = ConInventoryTransaction.TransType.ADJUSTMENT; invtm.TransDate = DateTime.Now; invtm.Remark = adjustd.Reason; invtm = InventoryTransactionRepo.CreateInventoryTransaction(invtm, out error); } entities.SaveChanges(); adjm = GetAdjustmentByID(adj.adjid, out error); nom.Deptid = DepartmentRepo.GetDepartmentByUserid(adj.raisedto ?? default(int), out error).Deptid; nom.Role = UserRepo.GetUserByUserID(adj.raisedby ?? default(int)).Role; nom.Title = "Adjustment Approval"; nom.NotiType = ConNotification.NotiType.Adjustment; nom.ResID = adj.adjid; nom = NotificationRepo.CreatNotification(nom, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(adjm); }