public async Task <IActionResult> Create([FromBody] EventParentDto model) { var currentUser = await _identityService.GetCurrentUser(); if (currentUser == null) { return(BadRequest(new { error = "You are not allowed!" })); } if (!ModelState.IsValid) { return(NotFound()); } if (model == null) { return(NotFound()); } var person = await _identityService.GetPersonByUserId(currentUser.Id); if (person == null) { return(BadRequest(new { error = "Person was not found" })); } var eventType = await _eventTypeService.GetEventTypeById(model.EventTypeId); if (eventType == null) { return(BadRequest(new { error = "Selected event type was not found" })); } var eventGenre = await _eventGenreService.GetEventGenreById(model.EventGenreId); if (eventGenre == null) { return(BadRequest(new { error = "Selected event eventParent was not found" })); } var location = await _locationService.GetLocationById(model.LocationId); if (location == null) { return(BadRequest(new { error = "Selected location was not found" })); } var eventTypeXEventGenreExists = await _eventTypeXEventGenreService.ExistsEventTypeXEventGenre(model.EventTypeId, model.EventGenreId); if (!eventTypeXEventGenreExists) { return(BadRequest(new { error = "Link between type and genre was not found" })); } bool result = Uri.TryCreate(model.PhotoURL, UriKind.Absolute, out Uri uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (result == false) { return(BadRequest(new { error = "Photo URL is not valid" })); } var eventParent = new EventParent() { Name = model.Name, Description = model.Description, Deleted = model.Deleted, PersonId = person.Id, EventTypeId = model.EventTypeId, EventGenreId = model.EventGenreId, LocationId = model.LocationId, DateAndHour = model.DateAndHour, PhotoURL = model.PhotoURL }; await _eventParentService.CreateEventParent(eventParent); return(Ok(eventParent)); }
public async Task <IActionResult> UpdateAsync([FromBody] EventParentDto model) { if (model == null) { return(NotFound()); } var currentUser = await _identityService.GetCurrentUser(); if (currentUser == null) { return(BadRequest(new { error = "You are not allowed!" })); } var person = await _identityService.GetPersonByUserId(currentUser.Id); if (person == null) { return(BadRequest(new { error = "Person was not found" })); } var eventParent = await _eventParentService.GetEventParentById(model.Id); if (eventParent == null) { return(BadRequest(new { error = "Selected eventParent was not found" })); } var eventType = await _eventTypeService.GetEventTypeById(model.EventTypeId); if (eventType == null) { return(BadRequest(new { error = "Selected event type was not found" })); } var eventGenre = await _eventGenreService.GetEventGenreById(model.EventGenreId); if (eventGenre == null) { return(BadRequest(new { error = "Selected event eventParent was not found" })); } var location = await _locationService.GetLocationById(model.LocationId); if (location == null) { return(BadRequest(new { error = "Selected location was not found" })); } bool result = Uri.TryCreate(model.PhotoURL, UriKind.Absolute, out Uri uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (result == false) { return(BadRequest(new { error = "Photo URL is not valid" })); } eventParent.Name = model.Name; eventParent.Description = model.Description; eventParent.EventGenreId = model.EventGenreId; eventParent.EventTypeId = model.EventTypeId; eventParent.LocationId = model.LocationId; eventParent.DateAndHour = model.DateAndHour; eventParent.PhotoURL = model.PhotoURL; await _eventParentService.UpdateEventParent(eventParent); return(Ok()); }