public ActionResult Create(StaticFilterCreateDTO filter) { if (ModelState.IsValid) { PredefinedStaticFilter newFilter = null; if (filter.FilterID != 0) { newFilter = this.db.StaticFilters.Find(filter.FilterID); if (newFilter.OwnerID != User.Identity.GetUserId()) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } } else { newFilter = new PredefinedStaticFilter(); } newFilter.From = UnixTime.ParseUnixTimestamp(filter.From); newFilter.To = UnixTime.ParseUnixTimestamp(filter.To); newFilter.OwnerID = User.Identity.GetUserId(); newFilter.ProjectID = filter.ProjectID; newFilter.TaskID = filter.TaskID; newFilter.UserID = filter.UserID; newFilter.Name = filter.Name; db.StaticFilters.Add(newFilter); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(filter)); }
// GET: Filters/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StaticFilterCreate viewModel = this.getCreateViewModel(); PredefinedStaticFilter filter = db.StaticFilters.Find(id); if (filter == null) { return(HttpNotFound()); } if (filter.OwnerID != User.Identity.GetUserId()) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } viewModel.ProjectID = filter.ProjectID; viewModel.TaskID = filter.TaskID; viewModel.To = filter.To?.ToUnixTimestamp() ?? 0; viewModel.From = filter.From?.ToUnixTimestamp() ?? 0; viewModel.UserID = filter.UserID; viewModel.FilterID = filter.FilterID; viewModel.Name = filter.Name; return(View("Create", viewModel)); }
public ActionResult DeleteConfirmed(int id) { PredefinedStaticFilter filter = db.StaticFilters.Find(id); if (filter.OwnerID != User.Identity.GetUserId()) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } db.StaticFilters.Remove(filter); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Filters/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PredefinedStaticFilter filter = db.StaticFilters.Find(id); if (filter == null) { return(HttpNotFound()); } if (filter.OwnerID != User.Identity.GetUserId()) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } return(View(filter)); }
// GET: Filters/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PredefinedStaticFilter filter = db.StaticFilters .Where(f => f.FilterID == id.Value) .Include(f => f.Project) .Include(f => f.Task) .Include(f => f.User) .FirstOrDefault(); if (filter == null) { return(HttpNotFound()); } if (filter.OwnerID != User.Identity.GetUserId()) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } return(View(filter)); }