public ActionResult Create([Bind(Include = "ID,FirstName,LastName,Age,Image,Specialty")] Author author, HttpPostedFileBase imageUpload) { bool isFileValid = true; if (ModelState.IsValid) { if (imageUpload != null && imageUpload.ContentLength > 0) { if (Utils.SaveImage(imageUpload)) { isFileValid = true; author.Image = imageUpload.FileName; } else { isFileValid = false; ModelState.AddModelError("", "The author image could not been saved."); } } if (isFileValid) { db.Authors.Add(author); db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(author)); }
public ActionResult BuyBook([Bind(Include = "ID,FirstName,LastName,Email,City,Street,PhoneNumber,BirthDate")] Customer customer, int?bookId) { if (ModelState.IsValid) { if (bookId != null) { var book = db.Books.Where(x => x.ID == bookId).Include(path => path.Customers).First(); if (book != null) { var cus = db.Customers.Find(customer.ID); if (cus != null) { if (!book.Customers.Any(x => x.ID == cus.ID)) { book.Customers.Add(cus); db.SaveChanges(); } } else { customer.CreationDate = DateTime.Now.Date; customer.BirthDate = customer.BirthDate.Date; book.Customers.Add(customer); db.SaveChanges(); } return(RedirectToAction("Index")); } } } return(RedirectToAction("BuyBook", new { bookId = bookId })); }
public IActionResult Post([FromBody] bookLocation bookLocation) { if (!ModelState.IsValid) { return(BadRequest()); } db.bookLocations.Add(bookLocation); db.SaveChanges(); return(CreatedAtAction("Post", new { id = bookLocation.bookID }, bookLocation)); }
public ActionResult Create([Bind(Include = "AuthorId,Name")] Author author) { if (ModelState.IsValid) { db.Authors.Add(author); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(author)); }
public ActionResult Create([Bind(Include = "GenreId,Name,Description")] Genre genre) { if (ModelState.IsValid) { db.Genres.Add(genre); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(genre)); }
public ActionResult Create([Bind(Include = "bookStoreNumber,bookID,bookStoreLocation,bookShelve,bookPhysical")] bookLocation bookLocation) { if (ModelState.IsValid) { db.bookLocations.Add(bookLocation); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.bookID = new SelectList(db.bookInfo, "bookID", "bookName", bookLocation.bookID); return(View(bookLocation)); }
public ActionResult Create([Bind(Include = "BookId,AuthorId,Title,NumOfPages,YearPublished,Price,Description")] Book book) { if (ModelState.IsValid) { db.Books.Add(book); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AuthorId = new SelectList(db.Authors, "AuthorId", "AuthorName", book.AuthorId); return(View(book)); }
public IHttpActionResult CreateDanhSach(SacheDto sache) { if (!ModelState.IsValid) { //throw new HttpResponseException(HttpStatusCode.BadRequest); return(BadRequest()); } var sach = MappingConfig.Mapping.Map <SacheDto, Sache>(sache); context.Saches.Add(sach); context.SaveChanges(); return(Created(new Uri(Request.RequestUri + "/" + sache.Id), sach)); // MappingConfig.Mapping.Map<Sache, SacheDto>(sache); }
public ActionResult Create([Bind(Include = "BookId,GenreId,AuthorId,Title,Price,BookArtUrl")] Book book) { if (ModelState.IsValid) { if (Request.Files.Count > 0) { var file = Request.Files[0]; } db.Books.Add(book); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(book)); }
public ActionResult Create([Bind(Include = "ID,FirstName,LastName,Email,City,Street,PhoneNumber,BirthDate,CreationDate")] Customer customer) { if (ModelState.IsValid) { if (db.Customers.Any(x => x.ID == customer.ID)) { ModelState.AddModelError("ID", "A customer with this ID already exist."); } else { customer.CreationDate = DateTime.Now; db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(customer)); }