public bool UpdateStatusOnRole(JuncUserRole objUserRole) { try { MasterRole _role = db.MasterRoles.Where(x => x.RoleID == objUserRole.RoleID).FirstOrDefault(); _role.RoleStatus = objUserRole.Status; db.SaveChanges(); return(true); } catch (Exception ex) { throw ex; } }
public bool InsertUserRole(JuncUserRole objUserRole) { try { foreach (JuncUserRole obj in db.JuncUserRoles.Where(x => x.UserID == objUserRole.UserID)) { db.JuncUserRoles.Remove(obj); } if (db.MasterRoles.Where(x => x.RoleID == objUserRole.RoleID && x.RoleStatus != objUserRole.Status).Count() > 0) { UpdateStatusOnRole(objUserRole); } db.JuncUserRoles.Add(objUserRole); db.SaveChanges(); BPEventLog bpe = new BPEventLog(); bpe.Object = "UserRoles"; bpe.ObjectName = GetRoles().Where(x => x.RoleID == objUserRole.RoleID).Select(y => y.RoleName).FirstOrDefault(); bpe.ObjectChanges = string.Empty; bpe.EventMassage = "Success"; bpe.Status = "A"; bpe.CreatedTimeStamp = DateTime.Now; new EventLogDAL().AddEventLog(bpe); return(true); } catch (Exception ex) { BPEventLog bpe = new BPEventLog(); bpe.Object = "UserRoles"; bpe.ObjectName = GetRoles().Where(x => x.RoleID == objUserRole.RoleID).Select(y => y.RoleName).FirstOrDefault(); bpe.ObjectChanges = string.Empty; bpe.EventMassage = "Failure"; bpe.Status = "A"; bpe.CreatedTimeStamp = DateTime.Now; new EventLogDAL().AddEventLog(bpe); throw ex; } }