public ActionResult Update(ObservationUpdateInput updateInput) { string observationId = VerbosifyId <Observation>(updateInput.Id); if (!_permissionManager.DoesExist <Observation>(observationId)) { return(HttpNotFound()); } if (!_userContext.HasGroupPermission <Observation>(PermissionNames.UpdateObservation, observationId)) { return(new HttpUnauthorizedResult()); } if (ModelState.IsValid) { _messageBus.Send( new ObservationUpdateCommand { Id = observationId, Title = updateInput.Title, Latitude = updateInput.Latitude, Longitude = updateInput.Longitude, Address = updateInput.Address, AnonymiseLocation = updateInput.AnonymiseLocation, Category = updateInput.Category, ObservedOn = updateInput.ObservedOn, UserId = _userContext.GetAuthenticatedUserId(), Projects = updateInput.ProjectIds, Media = updateInput.Media.Select(x => new ObservationMediaUpdateCommand() { MediaResourceId = x.MediaResourceId, Description = x.Description, Licence = x.Licence, IsPrimaryMedia = x.IsPrimaryMedia }) }); } else { Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; } dynamic viewModel = new ExpandoObject(); viewModel.Observation = updateInput; return(RestfulResult( viewModel, "observations", "update")); }
public ActionResult Create(ObservationUpdateInput createInput, IdentificationUpdateInput identificationCreateInput, SightingNoteUpdateInput sightingNoteCreateInput) { if (!_userContext.HasUserProjectPermission(PermissionNames.CreateObservation)) { return(new HttpUnauthorizedResult()); } Observation observation = null; if (ModelState.IsValid) { var key = string.IsNullOrWhiteSpace(createInput.Key) ? Guid.NewGuid().ToString() : createInput.Key; observation = _messageBus.Send <ObservationCreateCommand, Observation>(new ObservationCreateCommand() { Key = key, Title = createInput.Title, Latitude = createInput.Latitude, Longitude = createInput.Longitude, Address = createInput.Address, AnonymiseLocation = createInput.AnonymiseLocation, Category = createInput.Category, ObservedOn = createInput.ObservedOn, UserId = _userContext.GetAuthenticatedUserId(), Projects = createInput.ProjectIds, Media = createInput.Media.Select(x => new ObservationMediaUpdateCommand() { MediaResourceId = x.MediaResourceId, Key = x.Key, Description = x.Description, Licence = x.Licence, IsPrimaryMedia = x.IsPrimaryMedia }) }); if (identificationCreateInput.NewSightingIdentification) { _messageBus.Send( new IdentificationCreateCommand() { SightingId = observation.Id, UserId = _userContext.GetAuthenticatedUserId(), Comments = identificationCreateInput.IdentificationComments ?? string.Empty, IsCustomIdentification = identificationCreateInput.IsCustomIdentification, Taxonomy = identificationCreateInput.Taxonomy ?? string.Empty, Category = identificationCreateInput.Category ?? string.Empty, Kingdom = identificationCreateInput.Kingdom ?? string.Empty, Phylum = identificationCreateInput.Phylum ?? string.Empty, Class = identificationCreateInput.Class ?? string.Empty, Order = identificationCreateInput.Order ?? string.Empty, Family = identificationCreateInput.Family ?? string.Empty, Genus = identificationCreateInput.Genus ?? string.Empty, Species = identificationCreateInput.Species ?? string.Empty, Subspecies = identificationCreateInput.Subspecies ?? string.Empty, CommonGroupNames = identificationCreateInput.CommonGroupNames ?? new string[] {}, CommonNames = identificationCreateInput.CommonNames ?? new string[] {}, Synonyms = identificationCreateInput.Synonyms ?? new string[] {} }); } if (sightingNoteCreateInput.NewSightingNote) { _messageBus.Send( new SightingNoteCreateCommand() { SightingId = observation.Id, UserId = _userContext.GetAuthenticatedUserId(), Descriptions = sightingNoteCreateInput.Descriptions ?? new Dictionary <string, string>(), Tags = sightingNoteCreateInput.Tags ?? string.Empty, Comments = sightingNoteCreateInput.NoteComments ?? string.Empty }); } } else { Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; } dynamic viewModel = new ExpandoObject(); viewModel.Observation = new { Id = observation != null ? observation.Id : createInput.Id, createInput.Address, createInput.AnonymiseLocation, createInput.Category, createInput.Key, createInput.Latitude, createInput.Longitude, createInput.Media, createInput.ObservedOn, createInput.ProjectIds, createInput.Title }; if (identificationCreateInput.NewSightingIdentification) { viewModel.Identification = identificationCreateInput; } if (sightingNoteCreateInput.NewSightingNote) { viewModel.SightingNote = sightingNoteCreateInput; } return(RestfulResult( viewModel, "observations", "create")); }