public async Task <ActionResult> ChangeStatus(Guid id, bool upgrade) { var getContactQuery = new ContactDetailsQuery(id); var contact = await Mediator.Send(getContactQuery); if (contact == null) { return(NotFound("Lead not found")); } var getLeadQuery = new LeadDetailsQuery(contact); var lead = await Mediator.Send(getLeadQuery); if (lead.Contact.Status == "Invoice" && !lead.Order.Closed && upgrade) { return(BadRequest("Close the order before conversion.")); } else if (lead.Contact.Status == "Quote" && lead.Order == null && upgrade) { return(BadRequest("Add an order before upgrading lead to 'Invoice'.")); } else if (lead.Contact.Status == "Invoice" && lead.Order != null && lead.Order.Closed && !upgrade) { return(BadRequest("Order has been finalized. You can't downgrade the lead, please convert.")); } var changeStatusCommand = new ChangeStatusCommand(contact, upgrade); await Mediator.Send(changeStatusCommand); return(NoContent()); }
public async Task <ActionResult <LeadViewModel> > LeadDetails(Guid id) { var getContactQuery = new ContactDetailsQuery(id); var contact = await Mediator.Send(getContactQuery); if (contact == null) { return(NotFound("Lead not found.")); } var leadDetailsQuery = new LeadDetailsQuery(contact); var lead = await Mediator.Send(leadDetailsQuery); return(Mapper.Map <Lead, LeadViewModel>(lead)); }