// GET: CalendarCategorys/EditCategory/5 public ActionResult EditCategory(int?id) { try { if (Session["OrgId"] == null) { return(RedirectToAction("Signin", "Access")); } if (id != 0) { var edtCategory = db.CalendarCategorys.Where(x => x.CalendarCategoryId == id).FirstOrDefault(); var edtCategory1 = new CalendarCategory { CalendarCategoryId = edtCategory.CalendarCategoryId, CategoryName = edtCategory.CategoryName }; return(PartialView("~/Views/Shared/PartialViewsForms/_EditCalendarCategory.cshtml", edtCategory1)); } } catch (Exception e) { Console.WriteLine(e); return(Redirect("~/ErrorHandler.html")); } return(PartialView("~/Views/Shared/PartialViewsForms/_EditCalendarCategory.cshtml")); }
public ActionResult Edit(CalendarCategory calendarCategory) { try { if (Session["OrgId"] == null) { return(RedirectToAction("Signin", "Access")); } if ((int)Session["OrgId"] != 23) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (ModelState.IsValid) { db.Entry(calendarCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Table")); } } catch (Exception e) { Console.WriteLine(e); return(Redirect("~/ErrorHandler.html")); } return(View(calendarCategory)); }
public ActionResult Create(CalendarCategory calendarCategory) { try { if (ModelState.IsValid) { db.CalendarCategorys.Add(calendarCategory); db.SaveChanges(); return(RedirectToAction("Table")); } } catch (Exception e) { Console.WriteLine(e); return(View(calendarCategory)); } return(View(calendarCategory)); }
public async Task <ActionResult> UpdateCategoryAsync(int categoryId, CalendarCategory model) { if (!this.ModelState.IsValid) { return(this.InvalidModelState(this.ModelState)); } var meta = await AppUsers.GetCurrentAsync().ConfigureAwait(true); try { await CalendarCategoryModel.UpdateCategoryAsync(this.Tenant, meta, categoryId, model).ConfigureAwait(true); return(this.Ok()); } catch (Exception ex) { return(this.Failed(ex.Message, HttpStatusCode.InternalServerError)); } }
public static async Task UpdateCategoryAsync(string tenant, LoginView meta, int categoryId, CalendarCategory model) { int userId = meta.UserId; bool isMy = await BelongsToAsync(tenant, userId, categoryId).ConfigureAwait(false); if (!isMy) { throw new CalendarCategoryEditException(I18N.AccessIsDenied); } var poco = new Category { CategoryId = categoryId, CategoryName = model.CategoryName, ColorCode = model.ColorCode, AuditUserId = meta.UserId, UserId = meta.UserId, AuditTs = DateTimeOffset.UtcNow, IsLocal = true, Deleted = false }; await Categories.UpdateCategoryAsync(tenant, categoryId, poco).ConfigureAwait(false); }
public static async Task <int> AddCategoryAsync(string tenant, LoginView meta, CalendarCategory model) { var poco = new Category { CategoryName = model.CategoryName, ColorCode = model.ColorCode, AuditUserId = meta.UserId, UserId = meta.UserId, AuditTs = DateTimeOffset.UtcNow, IsLocal = true, Deleted = false }; int categoryId = await Categories.AddCategoryAsync(tenant, poco).ConfigureAwait(false); return(categoryId); }