コード例 #1
0
ファイル: UserDao.cs プロジェクト: vandanakumra/Pharma
        public bool UpdateRole(PharmaBusinessObjects.Master.Role role)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                try
                {
                    int result = 0;

                    Roles roles = context.Roles.Where(p => p.RoleId == role.RoleId).FirstOrDefault();

                    if (roles != null)
                    {
                        roles.RoleName  = role.RoleName;
                        roles.Status    = role.Status;
                        roles.CreatedBy = this.LoggedInUser.Username;
                        roles.CreatedOn = DateTime.Now;
                    }

                    result = context.SaveChanges();

                    var privledges = context.RolePrivledges.Where(p => p.RoleId == role.RoleId).ToList();

                    privledges.ForEach(p => context.RolePrivledges.Remove(p));

                    foreach (var item in role.PrivledgeList)
                    {
                        RolePrivledges priv = new RolePrivledges()
                        {
                            RoleId      = role.RoleId,
                            PrivledgeId = item.PrivledgeId
                        };
                    }

                    result = result + context.SaveChanges();

                    return(result > 0);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }
コード例 #2
0
ファイル: UserDao.cs プロジェクト: vandanakumra/Pharma
        public bool AddRole(PharmaBusinessObjects.Master.Role role)
        {
            using (PharmaDBEntities context = new PharmaDBEntities())
            {
                try
                {
                    int result = 0;

                    if (context.Roles.Any(p => p.RoleName.ToLower() == role.RoleName.ToLower()))
                    {
                        throw new Exception("Role already exists");
                    }

                    Roles roles = new Roles()
                    {
                        RoleName  = role.RoleName,
                        Status    = role.Status,
                        CreatedBy = this.LoggedInUser.Username,
                        CreatedOn = DateTime.Now
                    };

                    context.Roles.Add(roles);
                    result = context.SaveChanges();

                    foreach (Privledge item in role.PrivledgeList)
                    {
                        RolePrivledges priv = new RolePrivledges();
                        priv.RoleId      = roles.RoleId;
                        priv.PrivledgeId = item.PrivledgeId;
                        context.RolePrivledges.Add(priv);
                    }
                    result = result + context.SaveChanges();
                    return(result > 0);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    throw ex;
                }
            }
        }
コード例 #3
0
 public bool UpdateRole(PharmaBusinessObjects.Master.Role p)
 {
     return(new UserBiz(this.LoggedInUser).UpdateRole(p));
 }