Example #1
0
        public async Task<IActionResult> CreateClub()
        {
            if (ModelState.IsValid)
            {
                Club saveClub = new Club();
                string clubCookie = HttpContext.Request.Cookies["NewClub"];
                if (clubCookie != null)
                {
                    saveClub = clubCookie.FromJson<Club>();
                }
                else
                    return RedirectToAction("AddClub");
                SingleModelResponse<Club> clubResponse = await Task.Run(() => _context.SaveClub(saveClub));

                if (clubResponse.DidError == true || clubResponse == null)
                {
                    if (clubResponse == null)
                        return View("Error");
                    Error er = new Error(clubResponse.ErrorMessage);
                    return View("Error");
                }

                var CookieOption = new CookieOptions();
                CookieOption.Expires = DateTime.Now.AddDays(-1);
                CookieOption.HttpOnly = true;

                //set cookie
                HttpContext.Response.Cookies.Append("NewEvent", saveClub.ToJson(), CookieOption);
                var CookieOption2 = new CookieOptions();
                CookieOption.Expires = DateTime.Now.AddMinutes(1);
                CookieOption.HttpOnly = true;

                string source = "Add";
                //set cookie

                HttpContext.Response.Cookies.Append("SourcePageClub", source, CookieOption);

                return RedirectToAction("Clubs");
            }
            else
            {
                return BadRequest(ModelState);
            }
        }
Example #2
0
        public IActionResult AddClub([FromForm]Club ClubForm)
        {
            if (ModelState.IsValid)
            {
                Club club = new Club
                {
                    Name = ClubForm.Name,
                    Description = ClubForm.Description,
                    DateCreated = DateTime.Now.ToString(),
                    Location = ClubForm.Location,
                    UserId = _userManager.GetUserId(User),
                    Deleted = false
                };
                var CookieOption = new CookieOptions();
                CookieOption.Expires = DateTime.Now.AddMinutes(10);
                CookieOption.HttpOnly = true;

                //set cookie
                HttpContext.Response.Cookies.Append("NewClub", club.ToJson(), CookieOption);

                return RedirectToAction("FinalizeClub");
            }
            else
            {
                return View(ClubForm);
            }
        }