public async Task <IActionResult> Create([Bind("UserID,FirstName,LastName,Age,Address,Zip,City")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Create([Bind("CategoryID,Title")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("TagID,Name,Color")] Tag tag) { if (ModelState.IsValid) { _context.Add(tag); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tag)); }
public async Task <IActionResult> CreateShow([Bind("Title,AvailableTickets,Price,Date,ImageUrl,GenreId")] Show show) { if (ModelState.IsValid) { show.AdminId = (int)HttpContext.Session.GetInt32("AdminId"); db.Add(show); await db.SaveChangesAsync(); } ICollection <Show> shows = db.Shows.ToList(); return(View("Shows", shows)); }
public async Task <IActionResult> Create([Bind("FoodID,Title,Content,Price,Location,CategoryID,UserID")] Food food, List <IFormFile> files) { if (files != null) { foreach (var file in files) { if (file.Length > 0) { //Getting FileName string fileName = Path.GetFileName(file.FileName); //Assigning Unique Filename (Guid) var myUniqueFileName = fileName; //Getting file Extension var fileExtension = Path.GetExtension(fileName); // concatenating FileName + FileExtension var newFileName = String.Concat(myUniqueFileName, fileExtension); // Combines two strings into a path. var filepath = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploaded-images")).Root + $@"\{fileName}"; using (FileStream fs = System.IO.File.Create(filepath)) { file.CopyTo(fs); fs.Flush(); } food.Picture = fileName; } } } if (files.Count == 0) { ModelState.AddModelError("Picture", "Picture is required"); } if (ModelState.IsValid) { _context.Add(food); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "Title", food.CategoryID); ViewData["UserID"] = new SelectList(_context.Users, "UserID", "FirstName", food.UserID); return(View(food)); }