3 using Microsoft.AspNetCore.Authorization;
4 using Microsoft.AspNetCore.Mvc;
27 _scientificInternshipService = scientificInternshipService;
28 _userProfileService = userProfileService;
29 _departmentService = departmentService;
36 model.
Count = _scientificInternshipService.GetCountByRole(User);
48 var scientificInternship = _scientificInternshipService.GetById(
id.Value);
49 if (scientificInternship == null)
54 if (!UserHasPermission(scientificInternship))
59 return View(scientificInternship);
63 public IActionResult Create() => View();
67 [ValidateAntiForgeryToken]
70 if (!ModelState.IsValid)
75 _scientificInternshipService.CreateItem(model);
76 _scientificInternshipService.AddUser(
77 _scientificInternshipService.Get(si =>
79 _userProfileService.Get(User));
81 return RedirectToAction(nameof(Index));
85 public IActionResult
Edit(Guid?
id)
92 var scientificInternship = _scientificInternshipService.GetById(
id.Value);
93 if (scientificInternship == null)
98 if (!UserHasPermission(scientificInternship))
105 Users = _scientificInternshipService.GetUsers(scientificInternship.Id),
106 AllUsers = _userProfileService.GetAll()
112 [ValidateAntiForgeryToken]
115 if (
id != model.
Id || !_scientificInternshipService.Exists(
id))
120 var scientificInternship = _scientificInternshipService.GetById(
id);
121 if (!UserHasPermission(scientificInternship))
126 if (!ModelState.IsValid)
128 model.
Users = _scientificInternshipService.GetUsers(scientificInternship.Id);
129 model.
AllUsers = _userProfileService.GetAll();
133 _scientificInternshipService.UpdateItem(model);
134 return RedirectToAction(nameof(Index));
145 var scientificInternship = _scientificInternshipService.GetById(
id.Value);
146 if (scientificInternship == null)
151 if (!UserHasPermission(scientificInternship))
156 return View(scientificInternship);
160 [HttpPost, ActionName(
"Delete")]
161 [ValidateAntiForgeryToken]
164 if (!_scientificInternshipService.Exists(
id))
169 if (!UserHasPermission(_scientificInternshipService.GetById(
id)))
174 _scientificInternshipService.DeleteById(
id);
175 return RedirectToAction(nameof(Index));
187 var user = _userProfileService.GetById(request.UserId);
193 var scientificInternship = _scientificInternshipService.GetById(
id.Value);
194 if (scientificInternship == null)
199 if (!UserHasPermission(scientificInternship))
204 if (!_scientificInternshipService.GetUsers(scientificInternship.Id).Contains(user))
206 _scientificInternshipService.AddUser(scientificInternship, user);
221 var user = _userProfileService.GetById(request.UserId);
227 var publication = _scientificInternshipService.GetById(
id.Value);
228 if (publication == null)
233 if (!UserHasPermission(publication))
238 if (_scientificInternshipService.GetUsers(publication.Id).Contains(user))
240 _scientificInternshipService.RemoveUser(publication, user);
248 var user = _userProfileService.Get(User);
249 var department = _departmentService.Get(d => d.Staff.Contains(user));
250 return PageHelpers.IsAdmin(User) ||
251 PageHelpers.IsHeadOfDepartment(User) &&
ScientificInternshipController(IScientificInternshipService scientificInternshipService, IUserProfileService userProfileService, IDepartmentService departmentService)
IActionResult Index(ScientificInternshipIndexModel model)
IActionResult Details(Guid?id)
IEnumerable< DAL.Entities.ScientificInternship > ScientificInternships
IActionResult DeleteConfirmed(Guid id)
IActionResult Create(ScientificInternshipModel model)
IEnumerable< DAL.Entities.UserProfile.UserProfile > AllUsers
virtual ICollection< UserProfilesScientificInternships > UserProfilesScientificInternships
IActionResult RemoveUser(Guid?id, [FromBody] UpdateUserRequest request)
IActionResult Edit(Guid id, ScientificInternshipEditModel model)
IActionResult AddUser(Guid?id, [FromBody] UpdateUserRequest request)
IActionResult Edit(Guid?id)
IEnumerable< DAL.Entities.UserProfile.UserProfile > Users
IActionResult Delete(Guid?id)