public async Task <IActionResult> DeleteTicket(Guid id)
        {
            if (id == null)
            {
                _logger.LogError("Ticket id  sent from client is null.");
                return(BadRequest("Empty Ticket Cannot Be Deleted"));
            }
            var ticketExist = await _repo.Ticket.GetTicket(id);

            if (ticketExist == null)
            {
                _logger.LogError("Invalid ticket id");
                return(BadRequest("The ticket that you are trying to delete doesnot exist"));
            }

            var usersticketFromDatabase = await _repo.UserTicket.GetUserTicket(id);

            var isOwner = CheckTicketOwner.IsTicketOwner(User, usersticketFromDatabase);

            if (!isOwner)
            {
                return(Unauthorized("Sorry! You cannot modify this ticket"));
            }

            _repo.Ticket.DeleteTicket(ticketExist);
            await _repo.Save();

            return(Ok("Sucessfully Deleted Ticket"));
        }
        public async Task <IActionResult> UpdateTicket(Guid id, [FromBody] TicketForUpdateDto ticketToUpdate)
        {
            if (ticketToUpdate == null)
            {
                _logger.LogError("Ticket object sent from client is null.");
                return(BadRequest("Empty Ticket Cannot Be Created"));
            }
            if (!ModelState.IsValid)
            {
                _logger.LogError("Invalid model state for the Ticket");
                return(UnprocessableEntity(ModelState));
            }

            var originalTicket = await _repo.Ticket.GetTicket(id);

            if (originalTicket == null)
            {
                _logger.LogError("Invalid ticket id");
                return(BadRequest("The ticket that you are trying to update doesnot exist"));
            }

            //getting usertickets from database and check the owner
            var usersticketFromDatabase = await _repo.UserTicket.GetUserTicket(id);

            var isOwner = CheckTicketOwner.IsTicketOwner(User, usersticketFromDatabase);

            if (!isOwner)
            {
                return(Unauthorized("Sorry! You cannot modify this ticket."));
            }

            //updating the database so the previous record gets deleted in database
            _repo.UserTicket.RemoveTicketAndUser(usersticketFromDatabase);
            await _repo.Save();

            //Getting the username and email from jwt token to set it to created by name and email
            var userName  = User.Claims.ToList()[1].Value;
            var userEmail = User.Claims.ToList()[2].Value;

            ticketToUpdate.UpdatedByName  = userName;
            ticketToUpdate.UpdatedByEmail = userEmail;

            //Assigning previous submitted by value because the submitter name will get deleted when we apply put method
            //And dont have to use  this kind of trick for patch request but patch is little hard to implement
            var submmiteByName   = originalTicket.SubmittedByName;
            var submittedByEmail = originalTicket.SubmittedByEmail;

            ticketToUpdate.SubmittedByName  = submmiteByName;
            ticketToUpdate.SubmittedByEmail = submittedByEmail;
            ticketToUpdate.UpdatedAt        = DateTime.Now;
            //now updating data
            _mapper.Map(ticketToUpdate, originalTicket);

            await _repo.Save();

            return(Ok("Ticket Updated Sucessfully"));
        }