public string SaveUpdatePurchaseOrder(PurchaseOrderModel model) { string msg = ""; ShomaRMEntities db = new ShomaRMEntities(); int userid = ShomaRM.Models.ShomaGroupWebSession.CurrentUser != null ? ShomaRM.Models.ShomaGroupWebSession.CurrentUser.UserID : 0; if (model.POID == 0) { var SavePurchaseOrder = new tbl_PurchaseOrder() { PropertyID = model.PropertyID, OrderNumber = model.OrderNumber, Vendor = model.Vendor, PODesc = model.PODesc, PODate = model.PODate, TotalAmount = model.TotalAmount, Route = model.Route, ApprovedDate = model.ApprovedDate, ApprovedBy = model.ApprovedBy, CanceledDate = model.CanceledDate, CanceledBy = model.CanceledBy, CreatedBy = userid, CreatedDate = Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy")) }; db.tbl_PurchaseOrder.Add(SavePurchaseOrder); db.SaveChanges(); msg = "Purchase Order Save Successfully"; } else { var UpdatePurchaseOrder = db.tbl_PurchaseOrder.Where(co => co.POID == model.POID).FirstOrDefault(); if (UpdatePurchaseOrder != null) { UpdatePurchaseOrder.PropertyID = model.PropertyID; UpdatePurchaseOrder.OrderNumber = model.OrderNumber; UpdatePurchaseOrder.Vendor = model.Vendor; UpdatePurchaseOrder.PODesc = model.PODesc; UpdatePurchaseOrder.TotalAmount = model.TotalAmount; UpdatePurchaseOrder.Route = model.Route; UpdatePurchaseOrder.ApprovedDate = model.ApprovedDate; UpdatePurchaseOrder.ApprovedBy = model.ApprovedBy; UpdatePurchaseOrder.CanceledDate = model.CanceledDate; UpdatePurchaseOrder.CanceledBy = model.CanceledBy; db.SaveChanges(); msg = "Purchase Order Updated Successfully"; } } db.Dispose(); return(msg); }
public PurchaseOrderModel GetPurchaseOrderData(int Id) { ShomaRMEntities db = new ShomaRMEntities(); PurchaseOrderModel model = new PurchaseOrderModel(); var GetPurchaseOrderData = db.tbl_PurchaseOrder.Where(co => co.POID == Id).FirstOrDefault(); if (GetPurchaseOrderData != null) { model.PropertyID = GetPurchaseOrderData.PropertyID; model.OrderNumber = GetPurchaseOrderData.OrderNumber; model.Vendor = GetPurchaseOrderData.Vendor; model.PODesc = GetPurchaseOrderData.PODesc; model.PODate = GetPurchaseOrderData.PODate; model.TotalAmount = GetPurchaseOrderData.TotalAmount; model.Route = GetPurchaseOrderData.Route; model.ApprovedDate = GetPurchaseOrderData.ApprovedDate; model.ApprovedBy = GetPurchaseOrderData.ApprovedBy; model.CanceledDate = GetPurchaseOrderData.CanceledDate; model.CanceledBy = GetPurchaseOrderData.CanceledBy; } model.POID = Id; return(model); }