public ActionResult UpdateIdentification(IdentificationUpdateInput updateInput) { // TODO: Check permission to edit this note //if (!_userContext.HasGroupPermission<Observation>(PermissionNames.CreateSightingNote, updateInput.Id)) //{ // return new HttpUnauthorizedResult(); //} if (ModelState.IsValid) { _messageBus.Send( new IdentificationUpdateCommand() { Id = updateInput.Id.Value, SightingId = updateInput.SightingId, UserId = _userContext.GetAuthenticatedUserId(), Comments = updateInput.IdentificationComments, IsCustomIdentification = updateInput.IsCustomIdentification, Taxonomy = updateInput.Taxonomy ?? string.Empty, Category = updateInput.Category ?? string.Empty, Kingdom = updateInput.Kingdom ?? string.Empty, Phylum = updateInput.Phylum ?? string.Empty, Class = updateInput.Class ?? string.Empty, Order = updateInput.Order ?? string.Empty, Family = updateInput.Family ?? string.Empty, Genus = updateInput.Genus ?? string.Empty, Species = updateInput.Species ?? string.Empty, Subspecies = updateInput.Subspecies ?? string.Empty, CommonGroupNames = updateInput.CommonGroupNames ?? new string[] {}, CommonNames = updateInput.CommonNames ?? new string[] {}, Synonyms = updateInput.Synonyms ?? new string[] {} }); } else { Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; } dynamic viewModel = new ExpandoObject(); viewModel.Identification = updateInput; return(RestfulResult( viewModel, "identifications", "updateidentification")); }
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")); }