public ActionResult Delete(PluginDropDown pluginToDelete ) { //TODO: Fix... if (ModelState.IsValid) { Entities db = new Entities(); Plugin databasePlugin; try { databasePlugin = db.Plugins.Where(p => p.PluginGenerated == pluginToDelete.PluginGenerated).First(); } catch { return RedirectToAction("Delete", "Plugin", new { Message = DeleteMessageId.PluginErrorMessage }); } //retrieve string to delete file off server //update database first db.Plugins.Remove(databasePlugin); db.SaveChanges(); //if (System.IO.File.Exists(databasePluginFilePath)) //{ // try // { // System.IO.File.Delete(databasePluginFilePath); // return RedirectToAction("Delete", "Plugin", new { Message = DeleteMessageId.RemovePluginSuccess }); // } // catch // { // return RedirectToAction("Delete", "Plugin", new { Message = DeleteMessageId.RemovePluginFailure }); // } //} } //Default return. Once functionality is complete, this return should only be reached if something goes wrong return View("Delete"); }
//copied directly from ReportController with changes to work with plugin. Same functionality public ActionResult Delete(DeleteMessageId? message) { //Cookie cutter from Controllers/AccountControlller.cs, just changed to work with plugins. //Question mark is to allow for null values. //Good description here http://stackoverflow.com/questions/446835/what-do-two-question-marks-together-mean-in-c ViewBag.StatusMessage = message == DeleteMessageId.RemovePluginSuccess ? "Your Plugin was successfully removed." : message == DeleteMessageId.RemovePluginFailure ? "Your Plugin was not successfully removed." : ""; ViewBag.StatusFailure = message == DeleteMessageId.PluginErrorMessage ? "There was an error deleting your plugin, please try again." : ""; Entities db = new Entities(); var pluginIdConverter = db.Plugins.Local; //string pluginIdToString = pluginIdConverter.Select(c => c.PluginID).ToString(); var query = db.Plugins.Select(c => new SelectListItem { Value = c.PluginGenerated, Text = c.PluginName }); var model = new PluginDropDown { deleteList = query.ToList() }; return View(model); }