Beispiel #1
0
        public IActionResult OnPost(int id, DateTime date, string type, int capacity, string creating)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            GameNight gNight = new GameNight();

            gNight.GameNightId   = id;
            gNight.GameNightDate = date;
            gNight.GameNightType = type;
            gNight.Capacity      = capacity;
            gNight.Attendees     = 0;

            if (creating == "creating")
            {
                _unitOfWork.GameNights.Add(gNight);
                _unitOfWork.Save();
            }
            else
            {
                _unitOfWork.GameNights.Update(gNight);
                _unitOfWork.Save();
            }

            return(RedirectToPage("/Manage/GameNights/Index"));
        }
Beispiel #2
0
        public IActionResult OnGet(int id = 0)
        {
            gameNight = new GameNight();

            if (id != 0)
            {
                gameNight = _unitOfWork.GameNights.Get(id);
            }

            return(Page());
        }
        public async Task <ActionResult <GameNight> > PostGameNight(GameNight gameNight)
        {
            if (gameNight.MinimumPlayers < 2)
            {
                // RETURN A BAD REQUEST STATUS CODE
                return(BadRequest(new { Message = "You need at least 2 players!" }));
            }

            // Indicate to the database context we want to add this new record
            _context.GameNights.Add(gameNight);
            await _context.SaveChangesAsync();

            // Return a response that indicates the object was created (status code `201`) and some additional
            // headers with details of the newly created object.
            return(CreatedAtAction("GetGameNight", new { id = gameNight.Id }, gameNight));
        }
        public async Task <IActionResult> PutGameNight(int id, GameNight gameNight)
        {
            // If the ID in the URL does not match the ID in the supplied request body, return a bad request
            if (id != gameNight.Id)
            {
                return(BadRequest());
            }

            if (gameNight.MinimumPlayers < 2)
            {
                // RETURN A BAD REQUEST STATUS CODE
                return(BadRequest(new { Message = "You need at least 2 players!" }));
            }

            // Tell the database to consider everything in gameNight to be _updated_ values. When
            // the save happens the database will _replace_ the values in the database with the ones from gameNight
            _context.Entry(gameNight).State = EntityState.Modified;

            try
            {
                // Try to save these changes.
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                // Ooops, looks like there was an error, so check to see if the record we were
                // updating no longer exists.
                if (!GameNightExists(id))
                {
                    // If the record we tried to update was already deleted by someone else,
                    // return a `404` not found
                    return(NotFound());
                }
                else
                {
                    // Otherwise throw the error back, which will cause the request to fail
                    // and generate an error to the client.
                    throw;
                }
            }

            // Return a copy of the updated data
            return(Ok(gameNight));
        }
Beispiel #5
0
        public void OnPost(string userName, int gameNightId)
        {
            GameNight gn = _unitOfWork.GameNights.Get(gameNightId);

            GameNightAttendees gma    = new GameNightAttendees();
            string             userId = _unitOfWork.ApplicationUser.GetAll().Where(s => s.UserName == userName).Select(s => s.Id).FirstOrDefault();

            gma.User        = _unitOfWork.ApplicationUser.GetAll().Where(s => s.Id == userId).ToList().FirstOrDefault();
            gma.GameNightId = gameNightId;
            gma.GameNight   = gn;
            gma.username    = userName;
            _unitOfWork.Attendees.Add(gma);
            _unitOfWork.Save();

            _unitOfWork.GameNights.Update(gn);
            _unitOfWork.Save();

            gma = _unitOfWork.Attendees.GetAll().Reverse().ToList().Last();

            OnGet();
        }