public ActionResult Update(AlbumPO album) { //Defaulting redirect to index of album controller ActionResult OResponse = RedirectToAction("Index", "Album"); if (ModelState.IsValid) { try { //Updates album in datatable using valid user input. dataAccess.UpdateAlbum(AlbumMapper.MapPoToDO(album)); TempData["Message"] = "Album successfully updated."; } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "AlbumController", "Update", ex.StackTrace); OResponse = View(album); } } else { //Returns album to view. OResponse = View(album); } return(OResponse); }
public ActionResult Update(Album obj, HttpPostedFileBase file) { AlbumDAO dao = new AlbumDAO(); if (file != null && file.ContentLength > 0) { string fileName = Path.GetFileNameWithoutExtension(file.FileName); fileName += "_" + obj.IdAlbum; fileName += Path.GetExtension(file.FileName); string folderPath = Server.MapPath("~") + @"\Assets\images\ImagesOutSource\ImagesSong"; string folderPath2 = Server.MapPath("~") + @"\Assets\images\ImagesOutSource\Album"; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } string path = Path.Combine(folderPath, fileName); string path2 = Path.Combine(folderPath2, fileName); file.SaveAs(path); file.SaveAs(path2); obj.AnhAlbum = fileName; if (dao.UpdateAlbum(obj)) { return(RedirectToAction("Index", "Album")); } else { ModelState.AddModelError("", "Error"); return(View(obj.IdAlbum)); } } else { ModelState.AddModelError("", "Bạn phải nhập vào trường này"); } NgheSiDAO nsDAO = new NgheSiDAO(); var ns = nsDAO.Listof(); KhuVucDAO kvDAO = new KhuVucDAO(); var kv = kvDAO.ListOf(); ViewBag.ns = ns; ViewBag.kv = kv; return(View()); //try //{ // AlbumDAO dao = new AlbumDAO(); // if (dao.UpdateAlbum(ab)) // { // return RedirectToAction("Index", "Album"); // } // else // { // ModelState.AddModelError("", "Error"); // return View(ab.IdAlbum); // } }