//Add new record public static int AddRecord(eUsers eobj, string Groups) { int retval = 0; using (OneFineRateEntities db = new OneFineRateEntities()) { try { OneFineRate.tblUserM dbuser = (OneFineRate.tblUserM)OneFineRateAppUtil.clsUtils.ConvertToObject(eobj, new OneFineRate.tblUserM()); var dbobj = db.tblUserMs.SingleOrDefault(u => u.sUserName == dbuser.sUserName); if (dbobj != null) { return(2); } dbobj = db.tblUserMs.SingleOrDefault(u => u.sEmail == dbuser.sEmail); if (dbobj != null) { return(3); } db.tblUserMs.Add(dbuser); db.SaveChanges(); try { var obj = db.tblUserGroupMs.Where(u => u.iUserId == dbuser.iUserId); db.tblUserGroupMs.RemoveRange(obj); } catch (Exception) { } var grps = Groups.Split(',').ToList(); db.tblUserGroupMs.AddRange(grps.Select(x => new tblUserGroupM() { cStatus = "A", dtActionDate = DateTime.Now, dtCreationDate = DateTime.Now, iActionBy = dbuser.iActionBy, iCreatedBy = dbuser.iActionBy, iGroupId = Convert.ToInt32(x), iUserId = dbuser.iUserId })); db.SaveChanges(); retval = 1; } catch (Exception) { throw; } } return(retval); }
public static int UpdatePassword(int iUserId, string OldPassword, string NewPassword) { using (OneFineRateEntities db = new OneFineRateEntities()) { byte[] b = new byte[1]; string pass = SimpleHash.ComputeHash(OldPassword, "SHA1", b); var dbobj = (from s in db.tblUserMs select new { s.iUserId, s.sFirstName, s.sLastName, s.sUserName, s.sPassword, s.cStatus, s.dtActionDate, s.dtCreatedOn, s.iActionBy, s.sContact, s.sEmail }).Where(u => u.iUserId == iUserId && u.sPassword == pass).AsQueryable(); var list = dbobj.ToList(); if (list.Count == 0) { return(0); } else { OneFineRate.tblUserM obj = (OneFineRate.tblUserM)OneFineRateAppUtil.clsUtils.ConvertToObject(list[0], new OneFineRate.tblUserM()); obj.sPassword = SimpleHash.ComputeHash(NewPassword, "SHA1", b); obj.dtActionDate = DateTime.Now; obj.iActionBy = iUserId; db.tblUserMs.Attach(obj); db.Entry(obj).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(1); } }