public void LogRequest(HttpContext httpContext) { var log = new LogEntry { LoggingTime = DateTime.UtcNow, RequestVerb = httpContext.Request.Method, Ip = httpContext.Connection.RemoteIpAddress.ToString() }; dbContext.Add(log); dbContext.SaveChanges(); }
public async Task <Book> AddBookAsync(Book book) { var bookEntity = _context.Add(book); await _context.SaveChangesAsync(); return(bookEntity.Entity); }
public bool AddEdit(Category category) { if (category == null) { throw new NullReferenceException(); } try { if (category.Id == 0) { _storeContext.Add(category); _storeContext.SaveChanges(); return(true); } else { _storeContext.Entry(category).State = EntityState.Modified; _storeContext.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
public async Task <Genre> AddGenreAsync(Genre genre) { var genreEntity = _context.Add(genre); await _context.SaveChangesAsync(); return(genreEntity.Entity); }
public async Task <Author> AddAuthorAsync(Author author) { var authorEntity = _context.Add(author); await _context.SaveChangesAsync(); return(authorEntity.Entity); }
public async Task <Journal> AddJournalAsync(Journal journal) { var journalEntity = _context.Add(journal); await _context.SaveChangesAsync(); return(journalEntity.Entity); }
public async Task <Publisher> AddPublisherAsync(Publisher publisher) { var publisherEntity = _context.Add(publisher); await _context.SaveChangesAsync(); return(publisherEntity.Entity); }
public async Task Add(TE entity) { if (entity == null) { throw new ArgumentNullException("entity"); } m_context.Add(entity); await m_context.SaveChangesAsync(); }
public async Task <IActionResult> Create([Bind("Id,Name")] Genre genre) { if (ModelState.IsValid) { _context.Add(genre); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(genre)); }
public async Task <IActionResult> Create([Bind("Id,name,FirstName,LastName,DateOfBirth")] Author author) { if (ModelState.IsValid) { _context.Add(author); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(author)); }
public async Task <IActionResult> Create(VanChuyen vanChuyen) { if (ModelState.IsValid) { _db.Add(vanChuyen); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vanChuyen)); }
public async Task <IActionResult> Create(TacGia tacGia) { if (ModelState.IsValid) { _db.Add(tacGia); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tacGia)); }
public async Task <IActionResult> Create([Bind("ID,Name,Email,PhoneNoHome,PhoneNoWork,PhoneNoMobile,Address")] Supplier supplier) { if (ModelState.IsValid) { _context.Add(supplier); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(supplier)); }
public async Task <IActionResult> Create([Bind("Id,Title,Genre,Price,PublishDate")] Book book) { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(book)); }
public async Task <IActionResult> Create([Bind("CategoryId,CategoryName")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("Id,Title,Brand,Price,PublishDate")] Shirt tshirt) { if (ModelState.IsValid) { _context.Add(tshirt); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tshirt)); }
public async Task <IActionResult> Create([Bind("Name,Author,Id,Genre,Year")] Book book) { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(book)); }
public IActionResult Buy(Purchase purchase) { foreach (var item in _context.Book) { if (purchase.BookId == item.Id) { purchase.BookName = item.Name; break; } } if (ModelState.IsValid) { _context.Add(purchase); _context.SaveChanges(); //return View(purchase); return(View("Bought", purchase)); } return(View()); }
public async Task <IActionResult> Create([Bind("ID,Name,Email,PhoneNoHome,PhoneNoWork,PhoneNoMobile,Address,Active,Password,RoleID")] Account account) { if (ModelState.IsValid) { _context.Add(account); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["RoleID"] = new SelectList(_context.Roles, "ID", "ID", account.RoleID); return(View(account)); }
public async Task <IActionResult> Create([Bind("Id,Price,Edition,AuthorId,PublisherId")] Book book) { if (ModelState.IsValid) { _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AuthorId"] = new SelectList(_context.Authors, "Id", "Id", book.AuthorId); ViewData["PublisherId"] = new SelectList(_context.Publishers, "Id", "Id", book.PublisherId); return(View(book)); }
public IActionResult BuyAll(Purchase purchase) { List <Purchase> purchases = new List <Purchase>(); foreach (CartLine carline1 in cart.Lines) { //foreach (var item in _context.Book) //{ // if (carline1.Book.Id == item.Id) // { // purchase.BookName = item.Name; // break; // } //} purchases.Add(new Purchase() { User = purchase.User, Address = purchase.Address, ContactPhone = purchase.ContactPhone, BookId = carline1.Book.Id }); } for (int i = 0; i < purchases.Count; i++) { foreach (var item in _context.Book) { if (purchases[i].BookId == item.Id) { purchases[i].BookName = item.Name; break; } } } foreach (Purchase item in purchases) { if (!ModelState.IsValid) { _context.Add(item); _context.SaveChanges(); } else { return(View()); } } cart.Clear(); return(View("BoughtAll", purchase)); }
public bool SendMessage(GuestMessage message) { if (message != null) { try { _storeContext.Add(message); _storeContext.SaveChanges(); return(true); } catch (Exception) { return(false); } } return(false); }
public bool AddOrEdit(Book book) { if (book == null) { return(false); } try { if (book != null && book.ImgFile != null) { string number = string.Format( CultureInfo.CurrentCulture, "{0:d9}", (DateTime.Now.Ticks / 10) % 1000000000); //Destination FileName var fileName = Path.Combine(_hostingEnvironment.WebRootPath + "/images/books/", number + Path.GetExtension(book.ImgFile.FileName)); //FileStream fileStream = new FileStream(fileName, FileMode.Create); using (var strm = System.IO.File.Create(fileName)) { book.ImgFile.CopyTo(strm); } book.ImgUrl = "/images/books/" + number + Path.GetExtension(fileName); } if (book.Id == 0) { _bookStoreContext.Add(book); _bookStoreContext.SaveChanges(); return(true); } else { _bookStoreContext.Entry(book).State = EntityState.Modified; _bookStoreContext.SaveChanges(); return(true); } } catch { return(false); throw; } }
public bool AddEdit(Category category) { try { if (category.Id == 0) { _storeContext.Add(category); _storeContext.SaveChanges(); return(true); } else { _storeContext.Entry(category).State = EntityState.Modified; _storeContext.SaveChanges(); return(true); } } catch { return(false); } }
public async Task <IActionResult> Create([Bind("ID,Code,Name,Price,Description,Image,CategoryID,SupplierID")] Book book, IFormFile image) { if (ModelState.IsValid) { if (image != null && image.Length > 0) { var fileName = Path.GetRandomFileName() + Path.GetExtension(image.FileName); var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images", fileName); using (var fileSteam = new FileStream(filePath, FileMode.Create)) { await image.CopyToAsync(fileSteam); } book.Image = fileName; ViewData["FileName"] = fileName; } _context.Add(book); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "Name", book.CategoryID); ViewData["SupplierID"] = new SelectList(_context.Suppliers, "ID", "Name", book.SupplierID); return(View(book)); }
public bool AddOrEdit(Book book) { try { if (book.Id == 0) { _bookStoreContext.Add(book); _bookStoreContext.SaveChanges(); return(true); } else { _bookStoreContext.Entry(book).State = EntityState.Modified; _bookStoreContext.SaveChanges(); return(true); } } catch { return(false); throw; } }
public void Create(OrderItem item) { _bookStoreContext.Add(item); }
public async Task <IActionResult> Create([Bind("Id,Name,SoTrang,Image,Price,Discount,TheLoaiId,XuatBanId,TacGiaId")] Book book) { _context.Add(book); //await _context.SaveChangesAsync(); string webRootPath = _hostingEnvironment.WebRootPath; var files = HttpContext.Request.Form.Files; if (files.Count > 0) { //files has been uploaded var uploads = Path.Combine(webRootPath, "images"); var extension = Path.GetExtension(files[0].FileName); using (var filesStream = new FileStream(Path.Combine(uploads, book.Id + extension), FileMode.Create)) { files[0].CopyTo(filesStream); } book.Image = @"\images\" + book.Id + extension; } else { //no file was uploaded, so use default var uploads = Path.Combine(webRootPath, @"images\" + SD.DefaultBookImage); System.IO.File.Copy(uploads, webRootPath + @"\images\" + book.Id + ".png"); book.Image = @"\images\" + book.Id + ".png"; } //_context.Add(book); //await _context.SaveChangesAsync(); //string webRootPath = _hostingEnvironment.WebRootPath; //var files = HttpContext.Request.Form.Files; //var productsFromDb = _context.Books.Find(book.Id); //if (files.Count != 0) //{ // //Image has been uploaded // var uploads = Path.Combine(webRootPath, SD.ImageFolder); // var extension = Path.GetExtension(files[0].FileName); // using (var filestream = new FileStream(Path.Combine(uploads, book.Id + extension), FileMode.Create)) // { // files[0].CopyTo(filestream); // } // productsFromDb.Image = @"\" + SD.ImageFolder + @"\" + book.Id + extension; //} //else //{ // //when user does not upload image // var uploads = Path.Combine(webRootPath, SD.ImageFolder + @"\" + SD.DefaultBookImage); // System.IO.File.Copy(uploads, webRootPath + @"\" + SD.ImageFolder + @"\" + book.Id + ".png"); // productsFromDb.Image = @"\" + SD.ImageFolder + @"\" + book.Id + ".png"; //} await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); //ViewData["TacGiaId"] = new SelectList(_context.TacGias, "Id", "Name", book.TacGiaId); //ViewData["TheLoaiId"] = new SelectList(_context.TheLoais, "Id", "Name", book.TheLoaiId); //ViewData["XuatBanId"] = new SelectList(_context.XuatBans, "Id", "Name", book.XuatBanId); //return View(book); }
public async Task AddDiscountAsync(AbstractDiscount discount) { _context.Add(discount); await _context.SaveChangesAsync(); }
public void Create(T entity) { _context.Add(entity); Save(); }