//Get Single Record public static eGroups GetSingleRecordById(int id) { eGroups eobj = new eGroups(); using (OneFineRateEntities db = new OneFineRateEntities()) { var dbobj = db.tblGroupMs.SingleOrDefault(u => u.iGroupId == id); if (dbobj != null) { eobj = (eGroups)OneFineRateAppUtil.clsUtils.ConvertToObject(dbobj, eobj); } } return(eobj); }
//Add new record public static int AddRecord(eGroups eobj, string Menus) { int retval = 0; using (OneFineRateEntities db = new OneFineRateEntities()) { try { OneFineRate.tblGroupM dbGroup = (OneFineRate.tblGroupM)OneFineRateAppUtil.clsUtils.ConvertToObject(eobj, new OneFineRate.tblGroupM()); var dbobj = db.tblGroupMs.SingleOrDefault(u => u.sGroupName == dbGroup.sGroupName); if (dbobj != null) { return(2); } else { var mns = Menus.Split(',').ToList(); if (mns[0] != "") { db.tblGroupMs.Add(dbGroup); db.SaveChanges(); db.tblGroupMenuMs.AddRange(mns.Select(menu => new tblGroupMenuM { cStatus = "A", dtActionDate = DateTime.Now, dtCreationDate = DateTime.Now, iActionBy = dbGroup.iActionBy, iCreatedBy = dbGroup.iActionBy, iMenuId = Convert.ToInt32(menu), iGroupId = dbGroup.iGroupId })); db.SaveChanges(); retval = 1; } else { retval = 2; } } } catch (Exception) { throw; } } return(retval); }
//Update a record public static int UpdateRecord(eGroups eobj, string Menus) { int retval = 0; using (OneFineRateEntities db = new OneFineRateEntities()) { try { var mns = Menus.Split(',').ToList(); if (mns.Count > 1) { OneFineRate.tblGroupM obj = (OneFineRate.tblGroupM)OneFineRateAppUtil.clsUtils.ConvertToObject(eobj, new OneFineRate.tblGroupM()); db.tblGroupMs.Attach(obj); db.Entry(obj).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); try { var obj1 = db.tblGroupMenuMs.Where(u => u.iGroupId == obj.iGroupId); db.tblGroupMenuMs.RemoveRange(obj1); } catch (Exception) { } db.tblGroupMenuMs.AddRange(mns.Select(menu => new tblGroupMenuM { cStatus = "A", dtActionDate = DateTime.Now, dtCreationDate = DateTime.Now, iActionBy = obj.iActionBy, iCreatedBy = obj.iActionBy, iMenuId = Convert.ToInt32(menu), iGroupId = obj.iGroupId })); db.SaveChanges(); retval = 1; } else { retval = 2; } } catch (Exception) { throw; } } return(retval); }
public string UpdateGroups(int id, string Groupname, string Desc, bool Active, string Menus) { object result = null; string strReturn = string.Empty; try { eGroups Obj = new eGroups(); Obj = BL_Groups.GetSingleRecordById(id); Obj.sGroupName = Groupname; Obj.sDescription = Desc; //Obj.dtCreationDate = DateTime.Now; Obj.dtActionDate = DateTime.Now; Obj.cStatus = Active ? "A" : "I"; Obj.iActionBy = ((OneFineRateBLL.BL_Login.UserDetails)Session["UserDetails"]).iUserId; int i = BL_Groups.UpdateRecord(Obj, Menus); if (i == 1) { result = new { st = 1, msg = clsUtils.ErrorMsg("Group", 2) }; } else if (i == 2) { result = new { st = 0, msg = clsUtils.ErrorMsg("", 6) }; } else { result = new { st = 0, msg = clsUtils.ErrorMsg("Group", 0) }; } } catch (Exception) { result = new { st = 0, msg = clsUtils.ErrorMsg("", 3) }; } strReturn = OneFineRateAppUtil.clsUtils.ConvertToJson(result); return(strReturn); }