public async Task <ActionResult> Update([FromBody] LibraryFormModel model, int libraryId) { if (!Roles.IsLibrarian(User.Identity.Name) && !Roles.IsAdmin(User.Identity.Name)) { return(Forbid()); } var entity = Libraries.GetLibrary(libraryId); var location = Locations.GetLocation(model.LocationId); entity.Location = location; if (location == null) { return(NotFound()); } if (entity == null) { return(NotFound()); } Libraries.Update(entity, model); return(Accepted()); }
public Library Update(Library entity, LibraryFormModel model) { Mapper.Map(model, entity); Update(entity); SaveChanges(); return(entity); }
public async Task <ActionResult> Create([FromBody] LibraryFormModel model) { if (!Roles.IsLibrarian(User.Identity.Name) && !Roles.IsAdmin(User.Identity.Name)) { return(Forbid()); } var entity = Mapper.Map <Library>(model); var location = Locations.GetLocation(model.LocationId); if (location == null) { return(NotFound()); } entity.Location = location; Libraries.Create(entity); return(CreatedAtAction(nameof(Fetch), new { libraryId = entity.LibraryId }, Mapper.Map <LibraryFormModel>(entity))); }