public void OnAuthorization(AuthorizationFilterContext context) { if (_inputGroupType == GroupType.Company) { ICompanyService _companyService = context.HttpContext.RequestServices.GetService <ICompanyService>(); object companyName = context.RouteData.Values["companyId"] ?? context.HttpContext.Request.Query["companyId"]; int companyId = int.Parse(companyName.ToString()); var result = _companyService.IsUserAssignedToCompany(companyId, context.HttpContext.User.Identity.Name).GetAwaiter().GetResult(); if (result == false && context.HttpContext.User.Identity.Name != "SuperUser") { context.Result = new JsonResult("User is not a member of this group") { StatusCode = 403 }; return; } } else if (_inputGroupType == GroupType.Platoon) { ICompanyService _companyService = context.HttpContext.RequestServices.GetService <ICompanyService>(); IPlatoonService _platoonService = context.HttpContext.RequestServices.GetService <IPlatoonService>(); var companyId = int.Parse(context.HttpContext.Request.Query["companyId"].ToString()); var platoonId = int.Parse(context.HttpContext.Request.Query["platoonId"].ToString()); var result = _platoonService.IsUserAssignedToPlatoon(companyId, platoonId, context.HttpContext.User.Identity.Name).GetAwaiter().GetResult(); if (result == false && context.HttpContext.User.Identity.Name != "SuperUser") { context.Result = new JsonResult("User is not a member of this group") { StatusCode = 403 }; return; } } else { context.Result = new JsonResult(null) { StatusCode = 403 }; return; } }
#pragma warning disable CS1573 public async Task <IActionResult> GetOtherFolders([FromServices] IPlatoonService platoonService, [FromQuery, Required] int companyId, [FromQuery, Required] int?platoonId = null, [FromQuery] int?rootFolder = null) { if (platoonId != null) { if (!await platoonService.IsUserAssignedToPlatoon(companyId, (int)platoonId, User.Identity.Name)) { return(Forbid("You must be platoon member")); } } var folder = await _folderService.GetOtherFolder(companyId, platoonId, rootFolder); if (folder == null) { return(NotFound("Folder does not exist")); } return(Ok(folder)); }
/// <summary> /// Инициализация структур. /// </summary> public GameService(IArmyService army_service, IPlatoonService platoon_service) { _armyService = army_service; _platoonService = platoon_service; }
public PlatoonController(IPlatoonService platoonService) { _platoonService = platoonService; }
#pragma warning disable CS1573 public async Task <IActionResult> CreateFolder([FromServices] ICompanyService companyService, [FromServices] IPlatoonService platoonService, [FromBody] DTO_CreateFolder form) { if (string.IsNullOrEmpty(form.Name)) { return(BadRequest("Folder name is required")); } if (!await companyService.IsUserAssignedToCompany(form.CompanyId, User.Identity.Name)) { return(Forbid("You must be company member")); } if (form.PlatoonId != null) { if (!await platoonService.IsUserAssignedToPlatoon(form.CompanyId, (int)form.PlatoonId, User.Identity.Name)) { return(Forbid("You must be platoon member")); } } Katalog folder; try { folder = await _folderService.CreateFolder(form.CompanyId, form.PlatoonId, form.Name, form.RootFolderId); } catch (Exception ex) { return(BadRequest(ex)); } return(Ok(folder)); }
public RequestController(ICompanyService companyService, IPlatoonService platoonService, IRequestService requestService) { _companyService = companyService; _platoonService = platoonService; _requestService = requestService; }
public PlatoonServiceTest() { _unitService = new UnitService(); _platoonService = new PlatoonService(_unitService); }
public PlatoonController(IPlatoonService ips) { ps = ips; }
public RequestService(GenericRepo <Prosba> requestRepo, ICompanyService companyService, IPlatoonService platoonService) { _requestRepo = requestRepo; _companyService = companyService; _platoonService = platoonService; }
public ReadWriteService(IGameService game_service, IArmyService army_service, IPlatoonService platoon_service) { _platoonService = platoon_service; _armyService = army_service; _gameService = game_service; }
/// <summary> /// Инициализация структур. /// </summary> public ArmyService(IPlatoonService platoon_service) { _platoonService = platoon_service; }