public async Task <IActionResult> PutUser([FromRoute] Guid id, [FromBody] User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != user.Id) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([FromBody] CreateBookModel model) { model.Name = model.Name.ToLower(); if (await _dbContext.Books.AnyAsync(f => f.Name == model.Name)) { return(BadRequest("duplicated name")); } await _dbContext.Books.AddAsync(new Infrastructure.Book() { Name = model.Name, Code = model.Code, SectionId = model.SectionId, Note = model.Note, AuthorName = model.AuthorName, NamePrinting = model.NamePrinting, Date = model.Date, Path = model.Path, Photos = model.Photos, ShelfNumber = model.ShelfNumber }); await _dbContext.SaveChangesAsync(); return(Ok("Book successfuly created")); }
public async Task <IActionResult> Create([FromBody] CreateSectionModel model) { if (await _dbContext.Sections.AnyAsync(f => f.Name == model.Name)) { return(BadRequest("duplicated name")); } await _dbContext.Sections.AddAsync(new Infrastructure.Section() { Name = model.Name }); await _dbContext.SaveChangesAsync(); return(Ok("Section successfuly created")); }
public IActionResult Create(Library library) { db.Books.Add(library.Book); db.Authors.Add(library.Author); db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([FromBody] CreateUserModel model) { model.UserName = model.UserName.ToLower(); if (await _dbContext.Users.AnyAsync(f => f.UserName == model.UserName)) { return(BadRequest("duplicated username")); } await _dbContext.Users.AddAsync(new Infrastructure.User() { UserName = model.UserName, Password = model.Password, FullName = model.FullName, PolicyId = 1 }); await _dbContext.SaveChangesAsync(); return(Ok("user successfuly created")); }
public async Task <IActionResult> PostBook([FromBody] BookForEditAdmin book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var bookResult = _mapper.Map <BookForEditAdmin, Book>(book); _context.books.Add(bookResult); await _context.SaveChangesAsync(); return(CreatedAtAction("GetBook", new { id = bookResult.Id }, bookResult)); }
public async Task <bool> SaveAll() { return(await _context.SaveChangesAsync() > 0); }