public async Task <IActionResult> Create([Bind("Id,ObjectType,City,Street,BuildingNumber")] SportObject sportObject)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sportObject);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(sportObject));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ReserveDate(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var date = await _context.Dates.Include(m => m.Object)
                       .FirstOrDefaultAsync(m => m.Id == id);

            if (date == null)
            {
                return(NotFound());
            }


            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            var user = await _context.Users.FindAsync(userId);

            if (user == null)
            {
                return(NotFound());
            }

            var userReservations = from item in _context.Reservations where item.IdUser == userId select item;

            if (userReservations.Count() != 0)
            {
                return(View("ReservationWarning"));
            }

            var idReservation   = 0;
            var LastReservation = _context.Reservations.OrderByDescending(x => x.Id).FirstOrDefault();

            if (LastReservation == null)
            {
                idReservation = 1;
            }
            else
            {
                idReservation = LastReservation.Id + 1;
            }


            var NewReservation = new Reservation();

            NewReservation.Id     = idReservation;
            NewReservation.IdUser = user.Id;
            NewReservation.User   = user;
            NewReservation.IdDate = date.Id;
            NewReservation.Date   = date;

            await _context.Reservations.AddAsync(NewReservation);

            await _context.SaveChangesAsync();

            return(View("ReserveDate"));
        }
        public async Task <IActionResult> DeleteConfirmed(string id)
        {
            var user = await _context.Users.FindAsync(id);

            _context.Users.Remove(user);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create([Bind("Id,IdObject,StartDate,EndDate,MaxParticipants,IsReserved")] Date date)
        {
            if (ModelState.IsValid)
            {
                var sportObject = _context.SportObjects
                                  .Find(date.IdObject);

                if (sportObject == null)
                {
                    return(NotFound());
                }

                date.Object = sportObject;
                _context.Add(date);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(date));
        }
        public async Task <IActionResult> Create([Bind("Id,IdFrom,IdTo,Subject,Content")] Message message)
        {
            if (ModelState.IsValid)
            {
                var userTo = _context.Users
                             .Find(message.IdTo);

                if (userTo == null)
                {
                    return(NotFound());
                }

                message.UserTo = userTo;

                _context.Add(message);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(message));
        }
        public async Task <IActionResult> Create([Bind("Id,IdUser,IdDate,Acceptance")] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                var user = _context.Users.Find(reservation.IdUser);
                if (user == null)
                {
                    return(NotFound());
                }
                reservation.User = user;

                var date = _context.Dates.Find(reservation.IdDate);

                if (date == null)
                {
                    return(NotFound());
                }

                var sportObject = _context.SportObjects.Find(date.IdObject);
                if (sportObject == null)
                {
                    return(NotFound());
                }

                date.Object = sportObject;

                reservation.Date = date;


                _context.Add(reservation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(reservation));
        }