Пример #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 }));
        }
Пример #2
0
        public IActionResult create(CreateTicketDto m)
        {
            var ticket = _service.CreateTicket(m.StudentId, m.Issue);

            if (ticket != null)
            {
                return(CreatedAtAction(nameof(Get), new { Id = ticket.Id }, ticket));
            }
            return(BadRequest(new ErrorResponse {
                Message = "Ticket could not be created"
            }));
        }
 //[Authorize(Roles="Admin,Manager")]
 public IActionResult create(CreateTicketDto m)
 {
     if (ModelState.IsValid)
     {
         var result = _service.CreateTicket(m.StudentId, m.Issue);
         if (result != null)
         {
             //return CreatedAtAction(nameof(Get), new { Id = result.Id }, TicketDto.FromTicket(result));
             return(CreatedAtAction(nameof(Get), new { Id = result.Id }, result));
         }
     }
     return(BadRequest(ModelState));
 }
Пример #4
0
        public async Task <ActionResult <TicketDto> > Post(CreateTicketDto createTicketDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(createTicketDto));
            }

            var ticket = await _mediator.Send(new CreateTicketCommand
            {
                Ticket = _mapper.Map <Ticket>(createTicketDto)
            });

            return(Ok(_mapper.Map <TicketDto>(ticket)));
        }
Пример #5
0
        public async Task <IActionResult> CreateTicket([FromForm] CreateTicketDto CreateTicket)
        {
            try
            {
                if (CreateTicket == null)
                {
                    return(BadRequest("Ticket object is null"));
                }

                // convert incoming Dto to actual Model instance
                var createTicketEntity = _mapper.Map <TicketModel>(CreateTicket);

                // Algorithm for Tkt code

                //find comany of own  tkt
                var company = await _repository.Company.GetCompanyById(new Guid(CreateTicket.CompanyId));

                var TempCompanyName = company.CompanyName.Replace(" ", "_");

                var LastTktCode = await _repository.Ticket.GetTicketCodesByCondition(company.CompanyId);

                if (LastTktCode == null)
                {
                    createTicketEntity.TicketCode = TempCompanyName + 001;
                }
                else
                {
                    int getFinalTktCodeNum = Convert.ToInt32(LastTktCode.Replace(TempCompanyName, ""));
                    createTicketEntity.TicketCode = TempCompanyName + (getFinalTktCodeNum + 1);
                }


                _repository.Ticket.CreateTicket(createTicketEntity);

                if (CreateTicket.TktAttachment != null)
                {
                    // file exists
                    // PLAN:
                    // save file. return path. set path in TicketModel.TktAttachment.
                    var path = await _repository.Ticket.UploadAttachment(
                        CreateTicket.TktAttachment,
                        createTicketEntity.TicketId);

                    if (path != null) // save succesfull
                    {
                        createTicketEntity.TktAttachment = path;
                    }
                }

                await _repository.Save();

                // convert the model back to a DTO for output
                var createdTicket = _mapper.Map <TicketDto>(createTicketEntity);

                var username = User.Claims.FirstOrDefault(x => x.Type.Equals("UserName", StringComparison.InvariantCultureIgnoreCase)).Value;
                _repository.TicketTimeline.CreateTimelineEntry("tktCreated", createTicketEntity.TicketId, username);
                await _repository.Save();

                return(CreatedAtRoute("TicketById", new { id = createTicketEntity.TicketId }, createdTicket));
            }
            catch (Exception)
            {
                return(StatusCode(500, "Something went wrong"));
            }
        }