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))); }
public async Task <ActionResult> Create([FromBody] RoleFormModel model) { var entity = Mapper.Map <Role>(model); var user = Users.GetUser(model.UserId); var library = Libraries.GetLibrary(model.LibraryId); if (user == null) { return(NotFound()); } entity.User = user; if (library == null) { return(NotFound()); } entity.Library = library; Libraries.Create(entity); return(CreatedAtAction(nameof(Fetch), new { roleId = entity.RoleId }, Mapper.Map <RoleFormModel>(entity))); }