public async Task <IActionResult> TestIndex([FromForm] CreatePlaceResource resource) { Console.WriteLine($"Name: {resource.PlaceName}"); foreach (var r in resource.Sections) { Console.WriteLine($"Section: {r.SectionName} Rows: {r.RowsNumber} Seats: {r.SeatsInRow}"); } return(Ok("Test OK")); }
public async Task <bool> AddPlace(CreatePlaceResource resource) { _place = new Place { CreatorId = resource.UserId, Name = resource.PlaceName, OrganizatorId = resource.OrganizatorId, Sections = GenerateSections(resource.Sections).ToList() }; await _placeRepository.AddPlace(_place); return(true); }
public async Task <IActionResult> IndexAsync([FromForm] CreatePlaceResource resource) { if (!ModelState.IsValid) { return(BadRequest()); } var claimId = _claimsService.GetUserId(HttpContext.User.Identity as ClaimsIdentity); if (claimId == 0) { return(Unauthorized("You don't have permission to create a place")); } resource.UserId = claimId; var isAdminOfOrganization = await _administratorRepository.IsUserAdministratorOfOrganizator(resource.UserId, resource.OrganizatorId); if (!isAdminOfOrganization) { return(NotFound("You are not an administrator of this organizator")); } var isPlaceExists = await _placeRepository.IsPlaceExistsInOrganizator(resource.OrganizatorId, resource.PlaceName); if (isPlaceExists) { return(BadRequest("Place with this name already exists in this organizator")); } var IsSuccess = await _placeService.AddPlace(resource); if (IsSuccess) { return(Ok("Place was created")); } return(BadRequest("There was an unexpected error while creating place")); }