public async Task <IActionResult> Create(AutoSalon autoSalon) { if (!ModelState.IsValid) { return(View(autoSalon)); } if (autoSalon.Photo == null) { ModelState.AddModelError("Photo", "Please, select any image!"); return(View(autoSalon)); } if (!autoSalon.Photo.ContentType.Contains("image/")) { ModelState.AddModelError("Photo", "Image is not valid!"); return(View(autoSalon)); } autoSalon.Image = await autoSalon.Photo.SaveFileAsync(_env.WebRootPath); await _context.AutoSalons.AddAsync(autoSalon); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public ActionResult DeleteConfirmed(int id) { AutoSalon autoSalon = db.AutoSalon.Find(id); db.AutoSalon.Remove(autoSalon); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID,Naziv,Username,Password,Adresa,Telefon")] AutoSalon autoSalon) { if (ModelState.IsValid) { db.Entry(autoSalon).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(autoSalon)); }
public ActionResult Create([Bind(Include = "ID,Naziv,Username,Password,Adresa,Telefon")] AutoSalon autoSalon) { if (ModelState.IsValid) { db.AutoSalon.Add(autoSalon); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(autoSalon)); }
public async Task <IActionResult> Delete(int?id) { if (id == null) { NotFound(); } AutoSalon autoSalon = await _context.AutoSalons.FindAsync(id); if (autoSalon == null) { NotFound(); } return(View(autoSalon)); }
// GET: AutoSaloni/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AutoSalon autoSalon = db.AutoSalon.Find(id); if (autoSalon == null) { return(HttpNotFound()); } return(View(autoSalon)); }
public async Task <IActionResult> DeletePost(int?id) { if (id == null) { NotFound(); } AutoSalon autoSalon = await _context.AutoSalons.FindAsync(id); if (autoSalon == null) { NotFound(); } string path = _env.WebRootPath + @"\image\" + autoSalon.Image; if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } _context.AutoSalons.Remove(autoSalon); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int?id, AutoSalon autoSalon) { if (!ModelState.IsValid) { return(View(autoSalon)); } AutoSalon autoSalondb = await _context.AutoSalons.FindAsync(id); if (autoSalon.Photo != null) { if (autoSalon.Photo.ContentType.Contains("image/")) { string path = _env.WebRootPath + @"\image\" + autoSalondb.Image; if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } autoSalondb.Image = await autoSalon.Photo.SaveFileAsync(_env.WebRootPath); } else { ModelState.AddModelError("Photo", "Selected image is not valid!"); return(View(autoSalon)); } } autoSalondb.SalonName = autoSalon.SalonName; autoSalondb.Phone = autoSalon.Phone; autoSalondb.SecondaryPhone = autoSalon.SecondaryPhone; autoSalondb.Email = autoSalon.Email; autoSalondb.Address = autoSalon.Address; autoSalondb.Facebook = autoSalon.Facebook; autoSalondb.Instagram = autoSalon.Instagram; autoSalondb.Youtube = autoSalon.Youtube; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }