public InvLeatherTransferReceiveItem SetToBussinessObject(Inv_LeatherTransferReceiveItem Entity) { InvLeatherTransferReceiveItem Model = new InvLeatherTransferReceiveItem(); Model.ItemReceiveID = Entity.ItemReceiveID; Model.SupplierID = Entity.SupplierID; //Model.Supplier = _context.Sys_Supplier.Where(m => m.SupplierID == Entity.SupplierID).FirstOrDefault().SupplierName; Model.SupplierName = _context.Sys_Supplier.Where(m => m.SupplierID == Entity.SupplierID).FirstOrDefault().SupplierName; Model.ChallanID = Entity.ChallanID; Model.ChallanNo = Entity.ChallanID == null ? "" : _context.Prq_PurchaseChallan.Where(m => m.ChallanID == Entity.ChallanID).FirstOrDefault().ChallanNo; Model.PurchaseID = Entity.PurchaseID; Model.PurchaseNo = _context.Prq_Purchase.Where(m => m.PurchaseID == Entity.PurchaseID).FirstOrDefault().PurchaseNo; Model.ItemType = Entity.ItemType; Model.ItemTypeName = _context.Sys_ItemType.Where(m => m.ItemTypeID == Entity.ItemType).FirstOrDefault().ItemTypeName; Model.LeatherType = Entity.LeatherType; Model.LeatherTypeName = _context.Sys_LeatherType.Where(m => m.LeatherTypeID == Entity.LeatherType).FirstOrDefault().LeatherTypeName; Model.LeatherStatus = Entity.LeatherStatus; Model.LeatherStatusName = _context.Sys_LeatherStatus.Where(m => m.LeatherStatusID == Entity.LeatherStatus).FirstOrDefault().LeatherStatusName; Model.IssueQty = Entity.IssueQty; Model.IssueSide = Entity.IssueSide; Model.ReceiveQty = Entity.ReceiveQty; Model.ReceiveSide = Entity.ReceiveSide; Model.UnitID = Entity.UnitID; Model.UnitName = _context.Sys_Unit.Where(m => m.UnitID == Entity.UnitID).FirstOrDefault().UnitName; Model.Remarks = Entity.Remarks; return(Model); }
public ValidationMsg Save(InvLeatherTransferRecieve model, int userid) { _vmMsg = new ValidationMsg(); try { using (var tx = new TransactionScope()) { using (_context) { model.SetBy = userid; Inv_LeatherTransferRecieve tblLeatherTransferRecieve = SetToModelObject(model); _context.Inv_LeatherTransferRecieve.Add(tblLeatherTransferRecieve); _context.SaveChanges(); #region Save Detail Records if (model.LeatherTransferReceiveItemList != null) { foreach (InvLeatherTransferReceiveItem objInvLeatherTransferReceiveItem in model.LeatherTransferReceiveItemList) { objInvLeatherTransferReceiveItem.SetBy = userid; objInvLeatherTransferReceiveItem.ReceiveID = tblLeatherTransferRecieve.ReceiveID; Inv_LeatherTransferReceiveItem tblPurchaseYearPeriod = SetToModelObject(objInvLeatherTransferReceiveItem); _context.Inv_LeatherTransferReceiveItem.Add(tblPurchaseYearPeriod); } } _context.SaveChanges(); #endregion tx.Complete(); ReceiveID = tblLeatherTransferRecieve.ReceiveID; _vmMsg.Type = Enums.MessageType.Success; _vmMsg.Msg = "Save Successfully."; } } } catch { ReceiveID = 0; _vmMsg.Type = Enums.MessageType.Error; _vmMsg.Msg = "Failed to save."; } return(_vmMsg); }
public Inv_LeatherTransferReceiveItem SetToModelObject(InvLeatherTransferReceiveItem model) { Inv_LeatherTransferReceiveItem Entity = new Inv_LeatherTransferReceiveItem(); Entity.ItemReceiveID = model.ItemReceiveID; Entity.ReceiveID = model.ReceiveID;// Convert.ToInt16(_context.Inv_LeatherTransferRecieve.DefaultIfEmpty().Max(m => m.IssueID == null ? 0 : m.IssueID)); Entity.SupplierID = model.SupplierID; Entity.ChallanID = model.ChallanID; Entity.PurchaseID = model.PurchaseID; Entity.ItemType = model.ItemType; Entity.LeatherType = model.LeatherType; Entity.LeatherStatus = model.LeatherStatus; Entity.IssueQty = model.IssueQty; Entity.ReceiveQty = model.ReceiveQty; Entity.UnitID = model.UnitID; Entity.IssueSide = model.IssueSide; Entity.ReceiveSide = model.ReceiveSide; Entity.Remarks = model.Remarks; Entity.RecordStatus = "NCF";//model.RecordStatus; Entity.SetOn = DateTime.Now; Entity.SetBy = model.SetBy; Entity.IPAddress = string.Empty; return(Entity); }
public ValidationMsg Update(InvLeatherTransferRecieve model, int userid) { _vmMsg = new ValidationMsg(); try { using (var tx = new TransactionScope()) { using (_context) { Inv_LeatherTransferRecieve CurrentEntity = SetToModelObject(model); var OriginalEntity = _context.Inv_LeatherTransferRecieve.First(m => m.ReceiveID == model.ReceiveID); OriginalEntity.ReceiveDate = CurrentEntity.ReceiveDate;// Convert.ToDateTime(Convert.ToDateTime(CurrentEntity.ReceiveDate).ToString("dd/MM/yyyy")); OriginalEntity.ReceiveLocation = CurrentEntity.ReceiveLocation; OriginalEntity.SetBy = userid; OriginalEntity.SetOn = DateTime.Now; #region Save Detail Records if (model.LeatherTransferReceiveItemList != null) { foreach (InvLeatherTransferReceiveItem objInvLeatherTransferReceiveItem in model.LeatherTransferReceiveItemList) { if (objInvLeatherTransferReceiveItem.ItemReceiveID == 0) { objInvLeatherTransferReceiveItem.ReceiveID = model.ReceiveID; objInvLeatherTransferReceiveItem.SetBy = userid; Inv_LeatherTransferReceiveItem tblPurchaseYearPeriod = SetToModelObject(objInvLeatherTransferReceiveItem); _context.Inv_LeatherTransferReceiveItem.Add(tblPurchaseYearPeriod); } else { Inv_LeatherTransferReceiveItem CurEntity = SetToModelObject(objInvLeatherTransferReceiveItem); var OrgEntity = _context.Inv_LeatherTransferReceiveItem.First(m => m.ItemReceiveID == objInvLeatherTransferReceiveItem.ItemReceiveID); OrgEntity.ReceiveQty = CurEntity.ReceiveQty; OrgEntity.ReceiveSide = CurEntity.ReceiveSide; OrgEntity.SetBy = userid; OrgEntity.SetOn = DateTime.Now; } } } _context.SaveChanges(); #endregion tx.Complete(); _vmMsg.Type = Enums.MessageType.Update; _vmMsg.Msg = "Updated Successfully."; } } } catch { ReceiveID = 0; _vmMsg.Type = Enums.MessageType.Error; _vmMsg.Msg = "Failed to Update."; } return(_vmMsg); }