123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using UnivateProperties_API.Context;
- using UnivateProperties_API.Model.Users;
-
- namespace UnivateProperties_API.Repository.Users
- {
- public class UserRoleRepository : IRepository<UserRole>
- {
- private readonly DataContext _dbContext;
-
- public UserRoleRepository(DataContext dbc)
- {
- _dbContext = dbc;
- }
-
-
- public List<UserRole> GetAll()
- {
- return _dbContext.Roles.ToList();
- }
-
- public List<UserRole> Get(Func<UserRole, bool> where)
- {
- return _dbContext.Roles.Where(where).ToList();
- }
-
- public UserRole GetDetailed(Func<UserRole, bool> first)
- {
- return _dbContext.Roles.FirstOrDefault(first);
- }
-
- public List<UserRole> GetDetailedAll()
- {
- throw new NotImplementedException();
- }
-
- public void Insert(UserRole item)
- {
- if (item != null)
- {
- _dbContext.Roles.Add(item);
- Save();
- }
- }
-
- public void Insert(IEnumerable<UserRole> items)
- {
- if (items != null)
- {
- foreach (var item in items)
- {
- _dbContext.Roles.Add(item);
- }
- Save();
- }
- }
-
- public void Remove(UserRole item)
- {
- if (item != null)
- {
- _dbContext.Roles.Remove(item);
- Save();
- }
- }
-
- public void Remove(IEnumerable<UserRole> items)
- {
- if (items != null)
- {
- foreach (var item in items)
- {
- _dbContext.Roles.Remove(item);
- }
- Save();
- }
- }
-
- public void RemoveAtId(int item)
- {
- var role = _dbContext.Roles.Where(x => x.Id == item).FirstOrDefault();
- _dbContext.Roles.Remove(role);
- Save();
- }
-
- public void Update(UserRole item)
- {
- var curRole = _dbContext.Roles.Where(x => x.Id == item.Id).FirstOrDefault();
-
- if (curRole != item)
- {
- _dbContext.Roles.Update(item);
- Save();
- }
- }
-
- public void Save()
- {
- _dbContext.SaveChanges();
- }
- }
- }
|