public IActionResult PostCheckin([FromBody] CheckInCheckOut checkInCheckOut)
        {
            try
            {
                var alien = _context.Aliens.SingleOrDefault(e => e.Id == checkInCheckOut.IdAlien);
                if (alien is null)
                {
                    return(BadRequest("Alien não indentificado"));
                }

                var ballad = _context.Ballads.SingleOrDefault(e => e.Id == checkInCheckOut.IdBallad);
                if (ballad is null)
                {
                    return(BadRequest("Balada não indentificado"));
                }

                if (checkInCheckOut.IdObjectNotAllowed is not null)
                {
                    var objectNotAllowed = _context.ObjectNotAllowed.SingleOrDefault(e => e.Id == checkInCheckOut.IdObjectNotAllowed);
                    if (objectNotAllowed is null)
                    {
                        return(BadRequest("Objeto proibido não indentificado"));
                    }
                }

                if (!alien.AgeCheckMinimumAllowed())
                {
                    return(BadRequest("Idade minima para entrada não permitida"));
                }

                var CheckOut = _context.CheckInCheckOuts.SingleOrDefault(e => e.IdAlien == checkInCheckOut.IdAlien && e.DateTimeExit == null);
                if (CheckOut is not null)
                {
                    return(BadRequest("Alien já está em outra balada"));
                }

                checkInCheckOut.CheckIn();
                _context.CheckInCheckOuts.Add(checkInCheckOut);
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }


            return(Ok());
        }
Beispiel #2
0
 public IActionResult PostHasObjectNotAllowed([FromBody] ObjectNotAllowed objectNotAllowed)
 {
     _context.ObjectNotAllowed.Add(objectNotAllowed);
     _context.SaveChanges();
     return(Ok());
 }
 public IActionResult PostBallad([FromBody] Ballad ballad)
 {
     _context.Ballads.Add(ballad);
     _context.SaveChanges();
     return(Ok());
 }
 public IActionResult PostAlien([FromBody] Alien alien)
 {
     _context.Aliens.Add(alien);
     _context.SaveChanges();
     return(Ok());
 }