Example #1
0
        public IActionResult Patch(string id, [FromBody] UpdateTicketDto 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 user = _crudUsers.GetItem(model.User);
            var show = _crudShowings.GetItem(model.Showing);

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

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

            var ticket = new Tickets
            {
                Showing = show,
                User    = user,
                FieldX  = model.FieldX,
                FieldY  = model.FieldY,
                Status  = model.Status,
            };

            var entity = _crud.UpdateItem(id, ticket);

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