예제 #1
0
        public bool AssignPermissionToRole(int roleId, List <RolePermission> lstPermission)
        {
            bool result = false;

            try
            {
                using (var context = new DataLayerContext())
                {
                    var itemToRemove = context.RolePermissions.Where(x => x.RoleId == roleId).ToList();
                    foreach (RolePermission item in itemToRemove)
                    {
                        context.RolePermissions.Remove(item);
                        context.SaveChanges();
                    }

                    for (int per = 0; per < lstPermission.Count; per++)
                    {
                        context.RolePermissions.Add(lstPermission[per]);
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result = false;
            }
            return(result);
        }
예제 #2
0
        public void Add(User user)
        {
            User existingUser = FindById(user.Id);

            if (existingUser == default(User))
            {
                DataLayerContext.Add(user);
                DataLayerContext.SaveChanges();
            }
        }