Esempio n. 1
0
        public UserRoleGetModel Create(UserRolePostModel userRolePostModel)
        {
            UserRole toAdd = UserRolePostModel.ToUserRole(userRolePostModel);

            context.UserRoles.Add(toAdd);
            context.SaveChanges();
            return(UserRoleGetModel.FromUserRole(toAdd));
        }
Esempio n. 2
0
        public UserRoleGetModel GetById(int id)
        {
            UserRole userRole = context.UserRoles
                                .AsNoTracking()
                                .FirstOrDefault(ur => ur.Id == id);

            return(UserRoleGetModel.FromUserRole(userRole));
        }
Esempio n. 3
0
        public UserRoleGetModel Delete(int id)
        {
            var existing = context.UserRoles
                           .FirstOrDefault(ur => ur.Id == id);

            if (existing == null)
            {
                return(null);
            }

            context.UserRoles.Remove(existing);
            context.SaveChanges();

            return(UserRoleGetModel.FromUserRole(existing));
        }
Esempio n. 4
0
        public UserRoleGetModel Upsert(int id, UserRolePostModel userRolePostModel)
        {
            var existing = context.UserRoles.AsNoTracking().FirstOrDefault(urole => urole.Id == id);

            if (existing == null)
            {
                UserRole toAdd = UserRolePostModel.ToUserRole(userRolePostModel);
                context.UserRoles.Add(toAdd);
                context.SaveChanges();
                return(UserRoleGetModel.FromUserRole(toAdd));
            }

            UserRole Up = UserRolePostModel.ToUserRole(userRolePostModel);

            Up.Id = id;
            context.UserRoles.Update(Up);
            context.SaveChanges();
            return(UserRoleGetModel.FromUserRole(Up));
        }
Esempio n. 5
0
 public IEnumerable <UserRoleGetModel> GetAll()
 {
     return(context.UserRoles.Select(userRol => UserRoleGetModel.FromUserRole(userRol)));
 }