public ActionResult Create(DAL.Entities.Media media, int Category, HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { media.Path = Path.GetFileName(file.FileName); media.Url = Path.Combine(Server.MapPath("~/images"), file.FileName); //file.SaveAs(media.Url); } media.Category = new DAL.Entities.Category { Id = Category }; var result = unitOfWork.MediaRepository.Insert(media); if (result != null) { var data = unitOfWork.MediaRepository.GetAll(); return(Json(new { status = true, message = "Media added successfully", data })); } return(Json(new { status = false, message = "An error was encountered. Please try again later." })); }
public ActionResult Edit(DAL.Entities.Media media, int Category) { if (media is null) { return(Json(new { status = false, message = "Sorry, your request cannot be processed. Please try again." })); } if (media.Id <= 0) { return(Json(new { status = false, message = "Bad parameter was provided." })); } media.Category = new DAL.Entities.Category { Id = Category }; var result = unitOfWork.MediaRepository.Update(media); if (result is null) { return(Json(new { status = false, message = "Sorry, an error was encountered. Please try again." })); } var data = unitOfWork.MediaRepository.GetAll(); return(Json(new { status = true, message = "Media updated successfully.", data })); }