Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateTechnition(int id, TechnitionForListDto technitionForListDto)
        {
            //if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            //return Unauthorized();

            var technitionFromRepo = await _repo.GetTechnition(id);

            _mapper.Map(technitionForListDto, technitionFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating client {id} failed at save");
        }
        public async Task <IActionResult> AddTicketForClient(int userId, /*string title, string description, [FromForm]*/ TicketForCreationDto ticketForCreationDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var clientFromRepo = await _repo.GetClient(userId);

            /* Tickets newTicket = new Tickets()
             * {
             *  ticketForCreationDto.Title = title
             *  ticketForCreationDto.Description = description
             *
             * };*/

            var ticketToCreate = new Tickets
            {
                Title       = ticketForCreationDto.Title,
                Description = ticketForCreationDto.Description,
                Notes       = ticketForCreationDto.Notes,
                DateIssued  = DateTime.Now,
                //DateClossed =

                // Username = clientForRegisterDto.Username,
                //PhoneNumber = clientForRegisterDto.PhoneNumber,
                //Email = clientForRegisterDto.Email,
                //DateAdded = DateTime.Now,
                //Address = clientForRegisterDto.Address
            };



            var ticket = _mapper.Map <Tickets>(ticketToCreate);

            clientFromRepo.Tickets.Add(ticket);



            if (await _repo.SaveAll())
            {
                var ticketToReturn = _mapper.Map <TicketsForDetailedDto>(ticket);
                return(CreatedAtRoute("GetTicket", new { id = ticket.Id }, ticketToReturn));
            }

            return(BadRequest("Could not book ticket"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UpdateClient(int id, ClientForUpdateDto clientForUpdateDto)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var clientFromRepo = await _repo.GetClient(id);

            _mapper.Map(clientForUpdateDto, clientFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating client {id} failed at save");
        }