public IActionResult CreateEvent(EventViewModel model, int[] RouteId) { if (ModelState.IsValid) { if (model.EventRoutes == null) { model.EventRoutes = new List <EventRouteViewModel>(); TimeZoneInfo localZone = TimeZoneInfo.Local; model.Timezone = localZone.Id; //model.EventDateTime } foreach (int id in RouteId) { SingleModelResponse <Route> routeResponse = _routeContext.GetRoute(id); if (routeResponse.DidError == true || routeResponse == null) { if (routeResponse == null) { return(View("Error")); } Error er = new Error(routeResponse.ErrorMessage); return(View("Error")); } model.EventRoutes.Add(routeResponse.Model.ToEventRouteViewModel()); } if (model.ClubId != 0) { SingleModelResponse <Club> clubResponse = _clubContext.GetClub(model.ClubId); if (clubResponse.DidError == true || clubResponse == null) { if (clubResponse == null) { return(View("Error")); } Error er = new Error(clubResponse.ErrorMessage); return(View("Error")); } model.ClubName = clubResponse.Model.Name; } //example of using cookie var CookieOption = new CookieOptions(); CookieOption.Expires = DateTime.Now.AddMinutes(5); CookieOption.HttpOnly = true; //set cookie HttpContext.Response.Cookies.Append("NewEvent", model.ToJson(), CookieOption); return(RedirectToAction("FinalizeEvent")); } else { return(View(model)); } }
public ActionResult FinalizeEvent([FromBody] EventViewModel currentModel) { if (ModelState.IsValid) { string eventCookie = HttpContext.Request.Cookies["NewEvent"]; if (eventCookie != null) { EventViewModel memoryModel = eventCookie.FromJson <EventViewModel>(); if (memoryModel.ClubId != 0) { currentModel.ClubId = memoryModel.ClubId; currentModel.UserID = _userManager.GetUserId(User); } else { currentModel.UserID = _userManager.GetUserId(User); } } currentModel.DateCreated = DateTime.Now.ToString(); SingleModelResponse <Event> eventResponse = _context.SaveEvent(currentModel); if (eventResponse.DidError == true || eventResponse == null) { if (eventResponse == null) { return(View("Error")); } Error er = new Error(eventResponse.ErrorMessage); return(View("Error")); } var CookieOption = new CookieOptions(); CookieOption.Expires = DateTime.Now.AddDays(-1); CookieOption.HttpOnly = true; //set cookie HttpContext.Response.Cookies.Append("NewEvent", currentModel.ToJson(), CookieOption); CookieOption = new CookieOptions(); CookieOption.Expires = DateTime.Now.AddMinutes(1); CookieOption.HttpOnly = true; string source = "Add"; //set cookie HttpContext.Response.Cookies.Append("SourcePageEvent", source, CookieOption); return(RedirectToAction("Events")); } else { return(BadRequest()); } }