public ValidationMsg Save(SysChemicalItem model, int userid) { var vmMsg = new ValidationMsg(); try { Sys_ChemicalItem tblSysChemicalItem = SetToModelObject(model, userid); _context.Sys_ChemicalItem.Add(tblSysChemicalItem); _context.SaveChanges(); ItemID = tblSysChemicalItem.ItemID; vmMsg.Type = Enums.MessageType.Success; vmMsg.Msg = "Saved Successfully."; } catch (Exception ex) { if (ex.InnerException.InnerException.Message.Contains("UNIQUE KEY")) { vmMsg.Type = Enums.MessageType.Error; vmMsg.Msg = "HS Code Already Exit.."; } else { vmMsg.Type = Enums.MessageType.Error; vmMsg.Msg = "Failed to Save."; } } return(vmMsg); }
public ActionResult ChemicalItem(SysChemicalItem model) { if (model != null && model.ItemID != 0) { _vmMsg = _dalSysChemicalItem.Update(model, Convert.ToInt32(Session["UserID"])); } else { _vmMsg = _dalSysChemicalItem.Save(model, Convert.ToInt32(Session["UserID"])); } return(Json(new { ItemID = _dalSysChemicalItem.GetItemID(), msg = _vmMsg })); }
public SysChemicalItem SetToBussinessObject(Sys_ChemicalItem Entity) { SysChemicalItem Model = new SysChemicalItem(); Model.ItemID = Entity.ItemID; Model.HSCode = Entity.HSCode; Model.ItemName = Entity.ItemName; Model.ItemCategory = Entity.ItemCategory; if (Entity.ItemCategory == "RH") { Model.ItemCategoryName = "Raw Hide"; } else if (Entity.ItemCategory == "WB") { Model.ItemCategoryName = "Wet Bule"; } else if (Entity.ItemCategory == "CR") { Model.ItemCategoryName = "Crust"; } else if (Entity.ItemCategory == "FN") { Model.ItemCategoryName = "Finished"; } else if (Entity.ItemCategory == "CM") { Model.ItemCategoryName = "Common"; } else { Model.ItemCategoryName = "--Select--"; } Model.ItemTypeID = Entity.ItemTypeID; Model.UnitID = Entity.UnitID; Model.ItemTypeName = _context.Sys_ItemType.Where(m => m.ItemTypeID == Entity.ItemTypeID).FirstOrDefault() != null?_context.Sys_ItemType.Where(m => m.ItemTypeID == Entity.ItemTypeID).FirstOrDefault().ItemTypeName : null; Model.UnitName = _context.Sys_Unit.Where(m => m.UnitID == Entity.UnitID).FirstOrDefault() != null?_context.Sys_Unit.Where(m => m.UnitID == Entity.UnitID).FirstOrDefault().UnitName : null; Model.SafetyStock = Entity.SafetyStock; Model.ReorderLevel = Entity.ReorderLevel; Model.ExpiryLimit = Entity.ExpiryLimit; Model.IsActive = Entity.IsActive == true ? "Active" : "Inactive"; return(Model); }
public Sys_ChemicalItem SetToModelObject(SysChemicalItem model, int userid) { Sys_ChemicalItem entity = new Sys_ChemicalItem(); entity.ItemID = model.ItemID; entity.HSCode = model.HSCode; entity.ItemName = model.ItemName; entity.ItemCategory = model.ItemCategory; entity.ItemTypeID = model.ItemTypeID; entity.UnitID = model.UnitID; entity.SafetyStock = model.SafetyStock; entity.ReorderLevel = model.ReorderLevel; entity.ExpiryLimit = model.ExpiryLimit; entity.IsActive = model.IsActive == "Active"; entity.SetOn = DateTime.Now; entity.SetBy = userid; entity.IPAddress = string.Empty; return(entity); }
public ValidationMsg Update(SysChemicalItem model, int userid) { var vmMsg = new ValidationMsg(); try { var sysChemicalItem = _context.Sys_ChemicalItem.FirstOrDefault(s => s.ItemID == model.ItemID); if (sysChemicalItem != null) { sysChemicalItem.HSCode = model.HSCode; sysChemicalItem.ItemName = model.ItemName; sysChemicalItem.ItemCategory = model.ItemCategory; sysChemicalItem.ItemTypeID = model.ItemTypeID; sysChemicalItem.UnitID = model.UnitID; sysChemicalItem.SafetyStock = model.SafetyStock; sysChemicalItem.ReorderLevel = model.ReorderLevel; sysChemicalItem.ExpiryLimit = model.ExpiryLimit; sysChemicalItem.IsActive = model.IsActive == "Active"; sysChemicalItem.ModifiedOn = DateTime.Now; sysChemicalItem.ModifiedBy = userid; } _context.SaveChanges(); vmMsg.Type = Enums.MessageType.Update; vmMsg.Msg = "Updated Successfully."; } catch (Exception ex) { if (ex.InnerException.InnerException.Message.Contains("UNIQUE KEY")) { vmMsg.Type = Enums.MessageType.Error; vmMsg.Msg = "HS Code Already Exit."; } else { vmMsg.Type = Enums.MessageType.Error; vmMsg.Msg = "Failed to Update."; } } return(vmMsg); }