2 using System.Collections.Generic;
4 using System.Security.Claims;
28 public virtual IEnumerable<Grant>
GetAll()
30 return _grantRepository.All();
33 public virtual IEnumerable<Grant>
GetAllWhere(Func<Grant, bool> predicate)
35 return GetAll().Where(predicate);
40 IEnumerable<Grant> items;
43 items = _grantRepository.All();
47 var department = _departmentRepository.Get(r => r.Head.UserName == userClaims.Identity.Name);
48 items = _grantRepository.AllWhere(
49 a => a.UserProfilesGrants.Any(u => department.Staff.Contains(u.UserProfile))
54 var user = _userProfileRepository.Get(u => u.UserName == userClaims.Identity.Name);
55 items = _grantRepository.AllWhere(
56 a => a.UserProfilesGrants.Any(u => u.UserProfile.Id == user.Id)
63 public virtual IEnumerable<Grant>
GetPageByRole(
int page,
int count, ClaimsPrincipal userClaims)
65 return GetItemsByRole(userClaims).Skip((page - 1) * count).Take(count).ToList();
70 return GetItemsByRole(userClaims).Count();
75 return _grantRepository.Get(
id);
78 public virtual Grant Get(Func<Grant, bool> predicate)
80 return _grantRepository.Get(predicate);
85 _grantRepository.Create(
new Grant()
93 var grant = GetById(model.
Id);
99 grant.Info = model.
Info;
100 _grantRepository.Update(grant);
105 _grantRepository.Delete(
id);
110 return _grantRepository.Get(
id) != null;
115 if (grant == null || userProfile == null)
125 UserProfileId = userProfile.Id
127 _grantRepository.Update(grant);
132 if (grant == null || userProfile == null)
138 _grantRepository.Update(grant);
141 public virtual IEnumerable<UserProfile>
GetUsers(Guid
id)
143 var grant = _grantRepository.Get(
id);
144 IEnumerable<UserProfile> users = null;
147 users = grant.UserProfilesGrants.Select(u => u.UserProfile);
virtual void DeleteById(Guid id)
virtual void CreateItem(GrantModel model)
virtual int GetCountByRole(ClaimsPrincipal userClaims)
virtual IEnumerable< Grant > GetAll()
virtual IEnumerable< Grant > GetAllWhere(Func< Grant, bool > predicate)
virtual bool Exists(Guid id)
virtual IEnumerable< Grant > GetPageByRole(int page, int count, ClaimsPrincipal userClaims)
virtual Grant GetById(Guid id)
static bool IsHeadOfDepartment(ClaimsPrincipal user)
static bool IsAdmin(ClaimsPrincipal user)
GrantService(ScientificReportDbContext context)
virtual void UpdateItem(GrantEditModel model)
virtual Grant Get(Func< Grant, bool > predicate)
virtual ICollection< UserProfilesGrants > UserProfilesGrants
virtual IEnumerable< UserProfile > GetUsers(Guid id)
void AddUser(Grant grant, UserProfile userProfile)
void RemoveUser(Grant grant, UserProfile userProfile)
virtual IEnumerable< Grant > GetItemsByRole(ClaimsPrincipal userClaims)