public ActionResult Add(Media m, HttpPostedFileBase file) { string dbPath = "", path = ""; string fName = m.Name.ToLower().Replace(" ", "_"); string ext = ""; if (file != null) { ext = System.IO.Path.GetExtension(file.FileName); fName = ((m.Type == "I") ? "img_" : "fla_") + fName + ext; if (((m.Type == "I") ? Utils.Image.IsImage(ext) : ext.Equals(".swf"))) { path = Url.UploadPath(fName); try { file.SaveAs(path); dbPath = Url.Content(UrlHelperExtensions.ContentDirectory.data, fName); } catch { ModelState.AddModelError("", "An error occurred. Please try again in a few minutes."); } } } else { ModelState.AddModelError("", "File is not recognized"); } if (!string.IsNullOrEmpty(dbPath)) { DBDataContext db = Utils.DB.GetContext(); Media media = new Media() { Name = m.Name, Type = m.Type, Path = dbPath }; db.Medias.InsertOnSubmit(media); try { db.SubmitChanges(); return RedirectToAction("Index", "MediaLibrary", new { controller = "MediaLibrary", action = "Index" }); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); ErrorHandler.Report.Exception(ex, "MediaLibrary/Add"); } } else { ModelState.AddModelError("", "There has been an issue with uploading your Image/Video file. Please try again in few minutes."); } ViewData["Title"] = "Add Media"; ViewData["Action"] = "Add"; return View("Manage"); }
partial void UpdateMedia(Media instance);
partial void DeleteMedia(Media instance);
partial void InsertMedia(Media instance);