public ActionResult Create(File data) { string actionName = this.ControllerContext.RouteData.Values["action"].ToString(); string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); try { if (ModelState.IsValid) { FilesRepository fr = new FilesRepository(); UsersRepository ur = new UsersRepository(); var FileCreater = ur.GetUserByUsername(User.Identity.Name); data.User_id = FileCreater.Username; fr.AddFiles(data); //new LogsRepository().Log(User.Identity.Name, controllerName + "\\" + actionName, "Post" + data.Id + "added", LogType.Information); ViewBag.Message = "Item added successfully"; return(RedirectToAction("Upload", new { id = data.id })); } else { ViewBag.Error = "Check your inputs"; } } catch (Exception ex) { //new LogsRepository().Log(User.Identity.Name, controllerName + "\\" + actionName, ex, LogType.Error); ViewBag.Error = "Item failed to be added"; } return(View()); }
public ActionResult Delete(Guid id) { ProgrammesanaEntities1 db = new ProgrammesanaEntities1(); File file = db.Files.Find(id); db.Uploads.RemoveRange(file.Uploads); db.Files.Remove(file); db.SaveChanges(); return(RedirectToAction("Files")); /*Files.Where(x => x.id == f.id).FirstOrDefault(); * var uploads = db.Uploads.Where(b => b.File_id == e.id).AsEnumerable(); * foreach( var bk in uploads) * { * var b = bk; * e.Uploads.Remove(b); * } * db.Files.Remove(e); * db.SaveChanges(); * db.Dispose();*/ }
public ActionResult Edit(File file) { try { using (ProgrammesanaEntities1 db = new ProgrammesanaEntities1()){ var myFile = db.Files.Where(x => x.id == file.id).FirstOrDefault(); myFile.Title = file.Title; myFile.Description = file.Description; myFile.Date = file.Date; myFile.Share = file.Share; myFile.Categories_id = file.Categories_id; db.SaveChanges(); } return(RedirectToAction("Files")); } catch { return(View()); } }