public async Task <ActionResult> AbandonLead(Guid id, bool saveLead, bool keepRecords) { var loggedUserQuery = new LoggedUserQuery(); User user = await Mediator.Send(loggedUserQuery); var getLeadQuery = new ContactDetailsQuery(id); var lead = await Mediator.Send(getLeadQuery); if (lead == null) { return(NotFound("Lead not found.")); } Console.WriteLine(saveLead); foreach (var process in lead.CurrentSale) { if (process.OrderId != null) { return(BadRequest("Delete or close the order before cancelling this process.")); } } var abandonLead = new AbandonLeadCommand(user.Id, lead, saveLead, keepRecords); await Mediator.Send(abandonLead); return(NoContent()); }
public async Task <ActionResult> ShareTask(Guid id, string username) { var taskDetailsQuery = new TaskDetailsQuery(id); var task = await Mediator.Send(taskDetailsQuery); if (task == null) { return(NotFound("Task not found")); } var loggedUserQuery = new LoggedUserQuery(); User loggedUser = await Mediator.Send(loggedUserQuery); var getUserQuery = new GetUserQuery(username); User sharedWithUser = await Mediator.Send(getUserQuery); if (sharedWithUser == null) { return(NotFound("User to share the task with not found.")); } else if (task.UserTask.SharedWithId != null) { return(BadRequest("The task is shared already.")); } var shareTaskCommand = new ShareTaskCommand(task, loggedUser.Id, sharedWithUser); await Mediator.Send(shareTaskCommand); return(NoContent()); }
public async Task <ActionResult <CompleteTasksDataViewModel> > ListPendingTasks(int pendingActivePage, int pendingPageSize) { var loggedUserQuery = new LoggedUserQuery(); User user = await Mediator.Send(loggedUserQuery); var pendingTasksListQuery = new ListPendingTasksQuery(user.Id, pendingActivePage, pendingPageSize); var data = await Mediator.Send(pendingTasksListQuery); return(new CompleteTasksDataViewModel(Mapper.Map <List <DelegatedTask>, List <DelegatedTaskViewModel> >(data.Item1), data.Item2)); }
public async Task <ActionResult <List <LeadViewModel> > > ListLeads(bool allLeads, string status, string sortBy, CancellationToken ct) { var loggedUserQuery = new LoggedUserQuery(); User user = await Mediator.Send(loggedUserQuery); var listLeadsData = new ListLeadsQuery(user.Id, user.Level, allLeads, status, sortBy); var list = await Mediator.Send(listLeadsData); return(Mapper.Map <List <Lead>, List <LeadViewModel> >(list)); }
public async Task <ActionResult <CompleteContactsDataViewModel> > ListContacts(bool inProcess, bool premium, string orderBy, int?activePage, int?pageSize, string filterInput, bool uncontracted, CancellationToken ct) { var loggedUserQuery = new LoggedUserQuery(); User user = await Mediator.Send(loggedUserQuery); var completeContactsData = new ListContactsQuery(user, inProcess, premium, orderBy, activePage, pageSize, filterInput, uncontracted); var data = await Mediator.Send(completeContactsData); return(new CompleteContactsDataViewModel(Mapper.Map <List <Contact>, List <ContactViewModel> >(data.Item1), data.Item2)); }
public async Task <ActionResult <UserViewModel> > LoggedUser() { var loggedUserQuery = new LoggedUserQuery(); var user = await Mediator.Send(loggedUserQuery); if (user == null) { return(NotFound("User not found")); } return(Mapper.Map <User, UserViewModel>(user)); }
public async Task <ActionResult> AddLead([CustomizeValidator(Interceptor = typeof(API.Middleware.ValidatorInterceptor))] LeadViewModel lead) { var getLeadQuery = new GetContactByNameQuery(lead.Contact.Name); if (await Mediator.Send(getLeadQuery) != null) { return(BadRequest("This name is already taken.")); } var loggedUserQuery = new LoggedUserQuery(); User user = await Mediator.Send(loggedUserQuery); var addLeadCommand = new AddLeadCommand(user, lead.Contact.Name, lead.Contact.Company, lead.Contact.PhoneNumber, lead.Contact.Email, lead.Contact.Notes, lead.Contact.Source); await Mediator.Send(addLeadCommand); return(NoContent()); }
public async Task <ActionResult> AddOrder([CustomizeValidator(Interceptor = typeof(API.Middleware.ValidatorInterceptor))] OrderViewModel order) { var loggedUserQuery = new LoggedUserQuery(); User user = await Mediator.Send(loggedUserQuery); var getClientQuery = new GetContactByNameQuery(order.ClientName); var client = await Mediator.Send(getClientQuery); if (client == null) { return(NotFound("Client not found.")); } var addOrderCommand = new AddOrderCommand(client, order.Type, order.Product, order.Amount, order.Price, order.Notes); await Mediator.Send(addOrderCommand); return(NoContent()); }
public async Task <ActionResult> CloseOrder(Guid id) { var loggedUserQuery = new LoggedUserQuery(); User user = await Mediator.Send(loggedUserQuery); var getOrderQuery = new GetOrderQuery(id); var order = await Mediator.Send(getOrderQuery); if (order == null) { return(NotFound("Order not found")); } var closeOrderCommand = new CloseOrderCommand(order); await Mediator.Send(closeOrderCommand); return(NoContent()); }
public async Task <ActionResult> DeleteTask(Guid id) { var taskDetailsQuery = new TaskDetailsQuery(id); var task = await Mediator.Send(taskDetailsQuery); if (task == null) { return(NotFound("Task not found")); } var loggedUserQuery = new LoggedUserQuery(); User user = await Mediator.Send(loggedUserQuery); var deleteTaskCommand = new DeleteTaskCommand(user.UserName, task); await Mediator.Send(deleteTaskCommand); return(NoContent()); }
public async Task <ActionResult> UnshareContact(Guid id) { var contactDetailsQuery = new ContactDetailsQuery(id); var contact = await Mediator.Send(contactDetailsQuery); if (contact == null) { return(BadRequest("Contact not found")); } var loggedUserQuery = new LoggedUserQuery(); User user = await Mediator.Send(loggedUserQuery); var unshareContactCommand = new UnshareContactCommand(contact.Id, user.Id); await Mediator.Send(unshareContactCommand); return(NoContent()); }