public IActionResult CloseTicket(Guid id) { try { if (ModelState.IsValid) { TicketServiceResponseModel closeResponseReciever = _iticket.CloseTicketService(id); if (closeResponseReciever.code == responseCode.ErrorOccured) { return(BadRequest(closeResponseReciever.ticket, closeResponseReciever.Message, closeResponseReciever.code)); } else if (closeResponseReciever.code == responseCode.Successful) { return(Ok(closeResponseReciever.ticket, closeResponseReciever.Message, closeResponseReciever.code)); } else { return(BadRequest(null, "Error Occured", responseCode.ErrorOccured)); } } return(BadRequest(null, "Null Entity", responseCode.ErrorOccured)); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <IActionResult> ResolveTicket([FromBody] TicketViewModel ticket) { try { if (ModelState.IsValid) { TicketServiceResponseModel updateMethodServiceResponseModel = await _iticket.ResolveTicketService(ticket); if (updateMethodServiceResponseModel.code == responseCode.ErrorOccured) { return(BadRequest(updateMethodServiceResponseModel.ticket, updateMethodServiceResponseModel.Message, updateMethodServiceResponseModel.code)); } else if (updateMethodServiceResponseModel.code == responseCode.Successful) { return(Ok(updateMethodServiceResponseModel.ticket, updateMethodServiceResponseModel.Message, updateMethodServiceResponseModel.code)); } else { return(BadRequest(null, "Error Occured", responseCode.ErrorOccured)); } } return(BadRequest(null, "Null Entity", responseCode.ErrorOccured)); } catch (Exception ex) { return(BadRequest(ex)); } }
public IActionResult GetTicketById(Guid id) { try { if (ModelState.IsValid) { TicketServiceResponseModel getByIdResponseReciever = _iticket.GetTicketByIdService(id); if (getByIdResponseReciever.code == responseCode.ErrorOccured) { return(BadRequest(getByIdResponseReciever.ticket, getByIdResponseReciever.Message, getByIdResponseReciever.code)); } else if (getByIdResponseReciever.code == responseCode.Successful) { return(Ok(getByIdResponseReciever.ticket, getByIdResponseReciever.Message, getByIdResponseReciever.code)); } else { return(BadRequest("Error Occured", responseCode.ErrorOccured)); } } return(BadRequest("Null Entity", responseCode.ErrorOccured)); } catch (Exception ex) { return(BadRequest(ex)); } }
public TicketServiceResponseModel CloseTicketService(Guid id) { try { Ticket ticket = UnitOfWork.GetRepository <Ticket>().Single(p => p.Id == id); if (ticket == null) { ticketModel = new TicketServiceResponseModel() { ticket = null, Message = "Entity Does Not Exist", code = responseCode.ErrorOccured }; return(ticketModel); } else { if (ticket.Status == EntityStatus.Active) { ticket.Ticket_Status = Ticket_Status.Closed; UnitOfWork.GetRepository <Ticket>().Update(ticket); UnitOfWork.SaveChanges(); //Audit logger Guid idOfUserWhoClosed_Ticket = ticket.Resolvedby_Entityid.GetValueOrDefault(); _iauditExtension.Auditlogger(ticket.Company_Id, idOfUserWhoClosed_Ticket, "You Closed a Ticket"); ticketModel = new TicketServiceResponseModel() { ticket = null, Message = "Ticket Closed Successfully", code = responseCode.Successful }; return(ticketModel); } else { ticketModel = new TicketServiceResponseModel() { ticket = null, Message = "Entity Does Not Exist", code = responseCode.ErrorOccured }; return(ticketModel); } } } catch (Exception ex) { _loggerManager.LogError(ex.Message); throw; } }
//this service fetches ticket by there id public TicketServiceResponseModel GetTicketByIdService(Guid id) { try { Ticket ticket = UnitOfWork.GetRepository <Ticket>().Single(p => p.Id == id); //since i cant send company directly, i get the company and pass the values i need into the companyViewModel which i then return //CompanyViewModel companyViewModel = new CompanyViewModel //{ // Company_Name = company.Company_Name, // Id = company.Id //}; if (ticket != null) { if (ticket.Status == EntityStatus.Active) { ticketModel = new TicketServiceResponseModel() { ticket = ticket, Message = "Entity Fetched Successfully", code = responseCode.Successful }; return(ticketModel); } else { ticketModel = new TicketServiceResponseModel() { ticket = null, Message = "Entity Does Not Exist", code = responseCode.ErrorOccured }; return(ticketModel); } } ticketModel = new TicketServiceResponseModel() { ticket = null, Message = "Entity Does Not Exist", code = responseCode.ErrorOccured }; return(ticketModel); } catch (Exception ex) { _loggerManager.LogError(ex.Message); throw ex; } }
//this service creates new tickets public async Task <TicketServiceResponseModel> CreateTicketService(TicketViewModel ticket) { try { Company checkIfCompanyExists = UnitOfWork.GetRepository <Company>().Single(p => p.Id == ticket.Company_Id && p.Status == EntityStatus.Active); if (checkIfCompanyExists != null) { User checkIfUserExists = UnitOfWork.GetRepository <User>().Single(p => p.Id == ticket.Createdby_Userid && p.Status == EntityStatus.Active); if (checkIfUserExists != null) { Ticket toBeCreatedTicket = new Ticket { Company_Id = ticket.Company_Id, Customer_Id = ticket.Customer_Id, Createdby_Userid = ticket.Createdby_Userid, //Resolvedby_Entityid = ticket.Resolvedby_Entityid, Company_Name = checkIfCompanyExists.Company_Name, Ticket_Subject = ticket.Ticket_Subject, Ticket_Details = ticket.Ticket_Details, Ticket_Status = Ticket_Status.New, Status = EntityStatus.Active, CreatedAt = DateTime.Now, CreatedAtTimeStamp = DateTime.Now.ToTimeStamp(), UpdatedAt = DateTime.Now, UpdatedAtTimeStamp = DateTime.Now.ToTimeStamp(), }; //create email Customer customer = UnitOfWork.GetRepository <Customer>().Single(p => p.Id == ticket.Customer_Id && p.Status == EntityStatus.Active); string customerFullName = $"{customer.First_Name} {customer.Last_Name}"; var emailResponse = await _iEmailService.SendTicketCreatedEmail(customer.Email, "Ticket Created", new object[] { customerFullName, ticket.Ticket_Subject, ticket.Ticket_Details }); if (emailResponse != null) { UnitOfWork.GetRepository <Ticket>().Add(toBeCreatedTicket); UnitOfWork.SaveChanges(); //Audit Logger _iauditExtension.Auditlogger(toBeCreatedTicket.Company_Id, toBeCreatedTicket.Createdby_Userid, "You Created a Ticket"); ticketModel = new TicketServiceResponseModel() { ticket = toBeCreatedTicket, Message = "Ticket Created Successfully", code = responseCode.Successful }; return(ticketModel); } else { ticketModel = new TicketServiceResponseModel() { ticket = null, Message = "Email not sent, please check your network and try again.", code = responseCode.ErrorOccured }; return(ticketModel); } } else { ticketModel = new TicketServiceResponseModel() { ticket = null, Message = "Ticket Creator Do Not Exist", code = responseCode.ErrorOccured }; return(ticketModel); } } else { ticketModel = new TicketServiceResponseModel() { ticket = null, Message = "Company Do Not Exist", code = responseCode.ErrorOccured }; return(ticketModel); } } catch (Exception ex) { _loggerManager.LogError(ex.Message); throw; } }
//this service updates tickets public async Task <TicketServiceResponseModel> ResolveTicketService(TicketViewModel ticket) { try { Ticket toBeUpdatedTicket = UnitOfWork.GetRepository <Ticket>().Single(p => p.Id == ticket.Id); if (toBeUpdatedTicket == null) { ticketModel = new TicketServiceResponseModel() { ticket = null, Message = "Entity Does Not Exist", code = responseCode.ErrorOccured }; return(ticketModel); } else { if (toBeUpdatedTicket.Status == EntityStatus.Active) { if (toBeUpdatedTicket.Ticket_Status != Ticket_Status.Closed) { Company checkIfCompanyExists = UnitOfWork.GetRepository <Company>().Single(p => p.Id == toBeUpdatedTicket.Company_Id && p.Status == EntityStatus.Active); if (checkIfCompanyExists != null) { User checkIfResolverIsAUser = UnitOfWork.GetRepository <User>().Single(p => p.Id == ticket.Resolvedby_Entityid && p.Status == EntityStatus.Active); if (checkIfResolverIsAUser != null) { //Removed stuff from here Ticket extensionServiceResponse = await _iticket.TicketResolver(ticket); if (extensionServiceResponse != null) { ticketModel = new TicketServiceResponseModel() { ticket = extensionServiceResponse, Message = "Staff Response Sent Successfully", code = responseCode.Successful }; return(ticketModel); } else { ticketModel = new TicketServiceResponseModel() { ticket = null, Message = "Email not sent, please try again.", code = responseCode.ErrorOccured }; return(ticketModel); } } else { ticketModel = new TicketServiceResponseModel() { ticket = null, Message = "Resolvig User Does not Exist", code = responseCode.ErrorOccured }; return(ticketModel); } } else { ticketModel = new TicketServiceResponseModel() { ticket = toBeUpdatedTicket, Message = "Company Do Not Exist", code = responseCode.ErrorOccured }; return(ticketModel); } } else { ticketModel = new TicketServiceResponseModel() { ticket = null, Message = "This Ticket is Closed", code = responseCode.ErrorOccured }; return(ticketModel); } } else { ticketModel = new TicketServiceResponseModel() { ticket = null, Message = "Entity Does Not Exist", code = responseCode.ErrorOccured }; return(ticketModel); } } } catch (Exception ex) { _loggerManager.LogError(ex.Message); throw; } }