public async Task <IActionResult> CreatePhoto(CategoryViewModel viewModel) { if (ModelState.IsValid) { DateTime?PublishDate = null; if (viewModel.IsPublish == true) { PublishDate = DateTime.Now; } Category category = new Category() { Delete = false, CategoryName = viewModel.title, IsPublish = viewModel.IsPublish, Detailes = viewModel.Detailes, PublishDate = PublishDate, File = viewModel.File, }; await _context.Categories.AddAsync(category); await _context.SaveChangesAsync(); return(RedirectToAction("CreatePhoto")); } return(RedirectToAction("Index")); }
public async Task <IActionResult> PutBook(int id, Book book) { if (id != book.Id) { return(BadRequest()); } _context.Entry(book).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }
public async Task <IActionResult> Create([Bind("IdProducts,ProductsName,Image,Price,Unit")] Products products) { if (ModelState.IsValid) { _context.Add(products); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(products)); }
public async Task <IActionResult> Create([Bind("Id,Title,Type,From,TO,Description")] Books books) { if (ModelState.IsValid) { _context.Add(books); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(books)); }
public override async Task <BookModel> AddBook(AddBookRequest request, ServerCallContext context) { var book = _mapper.Map <Book>(request.Book); await _bookContext.Books.AddAsync(book); await _bookContext.SaveChangesAsync(); _logger.LogInformation("Book successfully added : {bookId}_{bookTitle}", book.BookId, book.Title); return(_mapper.Map <BookModel>(book)); }
public async Task <IActionResult> Create([Bind("LanguageID,LanguageName")] Language language) { if (ModelState.IsValid) { _context.Add(language); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(language)); }
public async Task <IActionResult> Create([Bind("ContactId,Name,Email,Message,DateCreate")] ContactMe contactMe) { if (ModelState.IsValid) { _context.Add(contactMe); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(contactMe)); }
public async Task <IActionResult> Create([Bind("")] Order order) { if (ModelState.IsValid) { _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(order)); }
public async Task <ActionResult> Create([Bind(Include = "Id,Name,Price")] Book book) { if (ModelState.IsValid) { db.Books.Add(book); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(book)); }
public async Task <ActionResult <Book> > Post(Book book) { if (book == null) { return(BadRequest()); } dbContext.Books.Add(book); await dbContext.SaveChangesAsync(); return(Ok(book)); }
public async Task <IActionResult> Create([Bind("Name,Price")] Want want) { if (ModelState.IsValid) { var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; want.OwnerId = userId; _context.Add(want); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(want)); }
public async Task <IActionResult> Create([Bind("Name,Price,SoldPrice,Content,Author")] Book book) { if (ModelState.IsValid) { var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; book.OwnerId = userId; // ViewBag.userId = userId; _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(book)); }
public async Task <IActionResult> Create([Bind("Orderid,Bookid")] OrderList orderList) { if (ModelState.IsValid) { if (orderList.Orderid != orderid) { return(NoContent()); } _context.Add(orderList); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(orderList)); }
/// <inheritdoc /> public async Task <Book> CreateBook(CreateBookDto bookToCreate) { var book = new Book { Title = bookToCreate.Title, Author = bookToCreate.Author, Category = bookToCreate.Category }; await _context.Books.AddAsync(book); await _context.SaveChangesAsync(); return(book); }
public async Task <Author> CreateAuthor(Author author) { EntityEntry <Author> entityEntry = await _context.Authors.AddAsync(author); await _context.SaveChangesAsync(); return(entityEntry.Entity); }
public async Task <IActionResult> Create(TranslatorsCreateViewModel ViewModel) { if (ModelState.IsValid) { Translator translator = new Translator() { Name = ViewModel.Name, Family = ViewModel.Family, }; _context.Translator.Add(translator); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(ViewModel)); }
public async Task <IActionResult> Create(BooksCreateEditViewModel ViewModel) { if (ModelState.IsValid) { List <Book_Translator> translators = new List <Book_Translator>(); List <Book_Category> categories = new List <Book_Category>(); if (ViewModel.TranslatorID != null) { translators = ViewModel.TranslatorID.Select(a => new Book_Translator { TranslatorID = a }).ToList(); } if (ViewModel.CategoryID != null) { categories = ViewModel.CategoryID.Select(a => new Book_Category { CategoryID = a }).ToList(); } DateTime?PublishDate = null; if (ViewModel.IsPublish == true) { PublishDate = DateTime.Now; } Book book = new Book() { //Delete = false, ISBN = ViewModel.ISBN, IsPublish = ViewModel.IsPublish, NumOfPages = ViewModel.NumOfPages, Stock = ViewModel.Stock, Price = ViewModel.Price, LanguageID = ViewModel.LanguageID, Summary = ViewModel.Summary, Title = ViewModel.Title, PublishYear = ViewModel.PublishYear, PublishDate = PublishDate, Weight = ViewModel.Weight, PublisherID = ViewModel.PublisherID, Author_Books = ViewModel.AuthorID.Select(a => new Author_Book { AuthorID = a }).ToList(), book_Tranlators = translators, book_Categories = categories, }; await _context.Books.AddAsync(book); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } else { ViewBag.LanguageID = new SelectList(_context.Languages, "LanguageID", "LanguageName"); ViewBag.PublisherID = new SelectList(_context.Publishers, "PublisherID", "PublisherName"); ViewBag.AuthorID = new SelectList(_context.Authors.Select(t => new AuthorList { AuthorID = t.AuthorID, NameFamily = t.FirstName + " " + t.LastName }), "AuthorID", "NameFamily"); ViewBag.TranslatorID = new SelectList(_context.Translator.Select(t => new TranslatorList { TranslatorID = t.TranslatorID, NameFamily = t.Name + " " + t.Family }), "TranslatorID", "NameFamily"); ViewModel.Categories = _repository.GetAllCategories(); return(View(ViewModel)); } }
public async Task <int> AddItemAsync(T item) { _table.Add(item); return(await _dbContext.SaveChangesAsync()); }
public async Task SaveChanges() { await context.SaveChangesAsync(); }
public async Task AddAsync(Book entity) { context.Books.Add(entity); await context.SaveChangesAsync(); }
public async Task AddAsync(Author entity) { context.Authors.Add(entity); await context.SaveChangesAsync(); }
public async Task SaveChanges() { await bookShopContext.SaveChangesAsync(); }
public async Task AddAsync(CoverType entity) { context.CoverTypes.Add(entity); await context.SaveChangesAsync(); }
public async Task <int> InsertAsync(T model) { _context.Set <T>().Add(model); return(await _context.SaveChangesAsync()); }
public async Task AddAsync(AgeCategory entity) { context.AgeCategories.Add(entity); await context.SaveChangesAsync(); }
public async Task AddAsync(Genre entity) { context.Genres.Add(entity); await context.SaveChangesAsync(); }