public IHttpActionResult Update(string id, AuthorPostRep resource) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } try { var @event = new AuthorUpdateEvent { Id = Guid.Parse(id), FirstName = resource.FirstName, LastName = resource.LastName, Country = resource.Country }; this._authorService.Update(@event); return(this.CreatedAtRoute(AuthorResourceNames.Routes.GetById, new { id = @event.Id }, new { })); } catch (FormatException) { return(this.BadRequest()); } catch (ObjectNotFoundException) { return(this.NotFound()); } catch (Exception ex) { return(this.InternalServerError(ex)); } }
public IHttpActionResult Create(AuthorPostRep resource) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } try { var @event = new AuthorCreateEvent { FirstName = resource.FirstName, LastName = resource.LastName, Country = resource.Country }; this._authorService.Add(@event); return(this.CreatedAtRoute(AuthorResourceNames.Routes.GetById, new { id = @event.Id }, resource)); } catch (Exception ex) { return(this.InternalServerError(ex)); } }
public async Task <ActionResult> Insert(Author obj) { var resource = new AuthorPostRep { FirstName = obj.FirstName, LastName = obj.LastName, Country = obj.Country }; var response = await _proxy.PostAsync("authors", resource : resource); if (response.IsSuccessStatusCode) { AuthorViewModel model = new AuthorViewModel(); var responseList = await this._proxy.GetAsync("authors"); dynamic responseContent = await responseList.Content.ReadAsAsync <Object>(); model.Authors = responseContent.Items.ToObject <List <Author> >(); model.SelectedAuthor = model.Authors.Find(o => o.Id == obj.Id); model.DisplayMode = "ReadOnly"; return(View("Index", model)); } return(View("Index")); }