Example #1
0
        public IActionResult Post([FromBody] CreateTicketDto model)
        {
            if (model == null)
            {
                return(BadRequest("No data"));
            }
            if (string.IsNullOrEmpty(model.Showing))
            {
                return(BadRequest("No Showing"));
            }
            if (string.IsNullOrEmpty(model.User))
            {
                return(BadRequest("No User"));
            }
            if (model.FieldX <= 0)
            {
                return(BadRequest("No fieldX"));
            }
            if (model.FieldY <= 0)
            {
                return(BadRequest("No fieldY"));
            }

            var placeIsFree = _crud.CheckIfFree(model.FieldX, model.FieldY, model.Showing);

            if (!placeIsFree)
            {
                return(BadRequest("Slot taken"));
            }

            var user = _crudUsers.GetItem(model.User);
            var show = _crudShowings.GetItem(model.Showing);

            if (show.Hall.SizeX < model.FieldX)
            {
                return(BadRequest("Wrong slot"));
            }
            if (show.Hall.SizeY < model.FieldY)
            {
                return(BadRequest("Wrong slot"));
            }

            var ticket = new Tickets
            {
                Showing = show,
                User    = user,
                FieldX  = model.FieldX,
                FieldY  = model.FieldY,
                Status  = model.Status,
            };
            var entity = _crud.AddItem(ticket);

            return(Ok(new { ticket = entity }));
        }