예제 #1
0
 public SingleModelResponse<Club> SaveClub(Club club)
 {
     string saveUrl = ClubUri + "CreateClub";
     var newClub = new Club
     {
         Name = club.Name,
         Description = club.Description,
         Location = club.Location,
         UserId = club.UserId,
         DateCreated = DateTime.Now.ToString()
     };
     var createdClub = PostContent(saveUrl, newClub);
     return createdClub;
 }
예제 #2
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);
            }
        }
예제 #3
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);
            }
        }
예제 #4
0
 public IActionResult AddClub()
 {
     string clubCookie = HttpContext.Request.Cookies["NewClub"];
     Club club = new Club();
     if (clubCookie != null)
     {
         club = clubCookie.FromJson<Club>();
     }
     return View(club);
 }
예제 #5
0
        public IActionResult Edit([FromBody]Club ClubForm)
        {
            if (ModelState.IsValid)
            {
                Club club = new Club
                {
                    ClubId = ClubForm.ClubId,
                    Description = ClubForm.Description,
                    Name = ClubForm.Name,
                    Location = ClubForm.Location,
                    DateCreated = ClubForm.DateCreated,
                    UserId = _userManager.GetUserId(User)
                };
                SingleModelResponse<Club> clubResponse = _context.UpdateClub(club);
                if (clubResponse.DidError == true || clubResponse == null)
                {
                    if (clubResponse == null)
                        return View("Error");
                    Error er = new Error(clubResponse.ErrorMessage);
                    return View("Error", er);
                }
                var CookieOption = new CookieOptions();
                CookieOption.Expires = DateTime.Now.AddMinutes(1);
                CookieOption.HttpOnly = true;

                string source = "Edit";
                //set cookie

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

                return RedirectToAction("ClubDetails", new { id = clubResponse.Model.ClubId });
            }
            else
            {
                return BadRequest();
            }
        }
예제 #6
0
 public SingleModelResponse<Club> UpdateClub(Club club)
 {
     string saveUrl = ClubUri + "Update/UpdateClub";
     var newClub = new Club
     {
         ClubId = club.ClubId,
         Name = club.Name,
         DateCreated = DateTime.Now.ToString(),
         Deleted = false,
         Description = club.Description,
         Location = club.Location,
         UserId = club.UserId
     };
     var updatedClub = PutContent(saveUrl, newClub);
     return updatedClub;
 }