/// <summary> /// Move lead to another stage /// </summary> /// <param name="leadId"></param> /// <param name="stageId"></param> /// <returns></returns> public virtual async Task <ResultModel> MoveLeadToStageAsync(Guid?leadId, Guid?stageId) { if (stageId == null) { return(new InvalidParametersResultModel()); } var lead = await _context.Leads.Include(i => i.LeadState) .Include(i => i.Team) .ThenInclude(i => i.TeamMembers) .FirstOrDefaultAsync(x => x.Id == leadId); if (lead == null) { return(new NotFoundResultModel()); } if (lead.StageId == stageId) { return(new SuccessResultModel <object>().ToBase()); } var stageRequest = await _crmPipeLineService.FindStageByIdAsync(stageId); if (!stageRequest.IsSuccess) { return(stageRequest.ToBase()); } var stage = stageRequest.Result; if (stage.Term != null) { lead.StageDeadLine = DateTime.Now.AddDays(stage.Term.Value); } lead.StageId = stageId.Value; _context.Leads.Update(lead); var result = await _context.PushAsync(); if (!result.IsSuccess) { return(result); } var newStage = await _context.Stages.FindByIdAsync(stageId); var listNotificationUserId = lead.Team.TeamMembers.Select(s => s.UserId); var notification = new Notification { Content = $"Lead {lead?.Name} change stage {stage?.Name} to {newStage?.Name}", Subject = "Info", NotificationTypeId = NotificationType.Info }; await _notify.SendNotificationAsync(listNotificationUserId, notification); await _notify.SendNotificationToSystemAdminsAsync(notification); return(result); }
public async Task <JsonResult> FindStageById([Required] Guid stageId) => await JsonAsync(_service.FindStageByIdAsync(stageId));