public ActionResult AddEditTask(int Id) { AdminTaskViewModel model = new AdminTaskViewModel(); model.Id = Id; model.CategoryList.Add(new SelectListItem() { Text = "-- Select Category --", Value = "0" }); foreach (var item in _otherSettingMethod.getAllSystemValueListByKeyName("Task Categories")) { model.CategoryList.Add(new SelectListItem() { Text = item.Value, Value = item.Id.ToString() }); } var employeeList = _employeeMethod.GetAllEmployeeList(); model.AssignToList.Add(new SelectListItem() { Text = "-- Select Assign To --", Value = "0" }); foreach (var item in employeeList) { model.AssignToList.Add(new SelectListItem() { Text = string.Format("{0} {1} - {2}", item.FirstName, item.LastName, item.SSOID), Value = item.Id.ToString() }); } model.InRelationToList.Add(new SelectListItem() { Text = "-- Select In Relation To --", Value = "0" }); foreach (var item in employeeList) { model.InRelationToList.Add(new SelectListItem() { Text = string.Format("{0} {1} - {2}", item.FirstName, item.LastName, item.SSOID), Value = item.Id.ToString() }); } model.StatusList.Add(new SelectListItem() { Text = "-- Select Status --", Value = "0" }); foreach (var item in _otherSettingMethod.getAllSystemValueListByKeyName("Task Status")) { model.StatusList.Add(new SelectListItem() { Text = item.Value, Value = item.Id.ToString() }); } if (model.Id > 0) { var taskDetail = _adminTaskMethod.getTaskById(Id); model.Title = taskDetail.Title; if (taskDetail.Category.HasValue == true) { model.CategoryId = (int)taskDetail.Category; } model.AssignToId = taskDetail.AssignTo; model.InRelationToId = taskDetail.InRelationTo; model.DueDate = String.Format("{0:dd-MM-yyy}", taskDetail.DueDate); model.StatusId = (int)taskDetail.Status; model.AlertBeforeDays = (int)taskDetail.AlterBeforeDays; model.Description = taskDetail.Description; var taskDoument = _adminTaskMethod.getTaskDocumentsByVisaId(Id); foreach (var item in taskDoument) { TaskDocumentViewModel docModel = new TaskDocumentViewModel(); docModel.Id = item.Id; docModel.originalName = item.OriginalName; docModel.newName = item.NewName; docModel.description = item.Description; model.DocumentList.Add(docModel); } } return(PartialView("_partialAddAdminTask", model)); }
private static async Task <ResultViewModel> SaveExternMessage(ServiceGateWayClient gatewayITask, TaskUser user, ClTaskDocument taskDocument, List <ClJoinFile> files, Dictionary <string, byte[]> filesForEmail, SendMessageViewModel model) { //Mail destiné à l'extérieur bool result = true; long employerNumber = model.EmployerNumber; long workerNumber = model.WorkerNumber; if (model.IsNewTask) { //change status to new when creating new task from draft if (model.TypeOfMessage == 8) { model.Status = 1; } //création de la tâche avant de créer l'élément de conversation si c'est un email direct long taskId = 0; var taskNew = new TaskDocumentViewModel { Task = new TaskViewModel { FormattedBeginDate = DateTime.MinValue.ToString("dd-MM-yyyy"), Description = model.CustomSubject, TechnicalId = model.TaskId, Type = 5, //par défaut - traitement d'email Priority = 2, ExpectedEndDate = DateTime.Now, BeginDate = DateTime.MinValue, EmployerNumber = employerNumber, WorkerNumber = workerNumber }, Affectation = new AffectationViewModel { SelectedAgent = user.Id, SelectedEntity = user.CurrentEntityIdTechnique.ToString() }, Context = user.CurrentContext, OrigineContext = user.CurrentOriginContext, CurrentStatus = model.Status, }; var mailTo = FormatStringToArrayWithoutDot(model.InternRecipient); // Si un seul employeur dans le To -> récupérer son n° d'employeur if (mailTo.Count() == 1 && employerNumber == 0) { employerNumber = gatewayITask.GetEmployerFromEmail(mailTo[0]); taskNew.Task.EmployerNumber = employerNumber; } // Mise à jour date début si nécessaire if (model.Status == 2) { taskNew.Task.BeginDate = DateTime.Now; taskNew.Task.FormattedBeginDate = DateTime.Now.ToString("dd-MM-yyyy"); } // Mise à jour date fin si nécessaire if (model.Status == 4) { if (employerNumber > 0) { taskNew.Task.EffectiveEndDate = DateTime.Now; taskNew.Task.FormattedEffectiveEndDate = DateTime.Now.ToString("dd-MM-yyyy"); } else { //changing to new when there is no employer model.Status = 1; taskNew.CurrentStatus = 1; } } result = await Task.Run(() => gatewayITask.InsertTaskDocument(MapClTaskDocumentToTaskDocumentViewModel.Map(taskNew), user.Id, ref taskId, user.CurrentEntityNumber)); } var externMail = new ClExternMail { Subject = model.DefaultSubject + " " + model.CustomSubject ?? "", MailBody = model.Message, Draft = model.TypeOfMessage == 8, //MailBodyText = "je stocke du texte" + model.Message, From = user.Email, Recipient = FormatStringToArrayWithoutDot(model.InternRecipient), joinFiles = files.ToArray(), CopyCc = FormatStringToArray(model.StringCopyTo), MailBodyIsHtml = true }; // Si le n° d'employeur trouvé est <> 0 et si nouvelle tâche // -> aller mettre ce n° d'employeur dans les pièces jointes // Si le n° d'employeur n'a pas déjà été garni if (employerNumber != 0 && model.IsNewTask) { foreach (var currentFile in externMail.joinFiles) { if (currentFile.Document == null) { currentFile.Document = new ClDocument(); ClEmployerDetail currentEmployer = new ClEmployerDetail(); currentEmployer.EmployeurNumber = employerNumber; currentFile.Document.EmployerList = new ClEmployerDetail[1]; currentFile.Document.EmployerList[0] = currentEmployer; currentFile.WithIndexing = true; } } } var conversationIdTechnic = await Task.Run(() => gatewayITask.AddExternMail(taskDocument, externMail, user.Id)); if (model.TypeOfMessage == 8 && conversationIdTechnic != -1) { //if draft is created from a draft, the older draft is removed if (model.IsDraft && model.TaskContributeId > 0) { gatewayITask.DeleteConversation(model.TaskContributeId, user.IdAgent); } return(new ResultViewModel() { NoError = true, Message1 = "Draft Created" }); } if (conversationIdTechnic != -1) { model.Recipient = externMail.Recipient; //model.CopyTo = externMail.CopyCc; model.Message = externMail.MailBody; //Récupérer tout les utilisateurs de Task List <ClAgent> allAgentsGroupsList = new List <ClAgent>(); //Récupération en session des agents if (HttpContext.Current.Session["AllAgentsGroupsListTrueIntercept"] == null) { allAgentsGroupsList = gatewayITask.GetAllTaskUser(true).ToList(); HttpContext.Current.Session["AllAgentsGroupsListTrueIntercept"] = allAgentsGroupsList; } else { allAgentsGroupsList = (List <ClAgent>)HttpContext.Current.Session["AllAgentsGroupsListTrueIntercept"]; } // Boucler sur les personnes en Cc et les retirer si ce sont des utilisateurs de Task List <string> CopyCcList = new List <string>(); foreach (var currentCc in externMail.CopyCc) { if (allAgentsGroupsList.Count(p => p.Mail.ToLower() == currentCc.ToLower()) == 0) { CopyCcList.Add(currentCc); } } model.CopyTo = CopyCcList.ToArray(); model.ConversationIdTech = conversationIdTechnic; model.UserId = user.Id; var mailReturn = await Task.Run(() => ManageMail.SendMailAndImage(model, user.Email, filesForEmail)); //element de conversation bien crée et mail bien envoyé if (mailReturn) { //delete the draft message after sending the mail without errors if (model.IsDraft && model.TaskContributeId > 0) { var draftDeleted = gatewayITask.DeleteConversation(model.TaskContributeId, user.IdAgent); } return(new ResultViewModel { NoError = mailReturn, Message1 = "" }); } else { //element de conversation bien crée et PROBLEME envoi mail return(new ResultViewModel { NoError = false, Message1 = "ERROR_SEND_MAIL_AFTER" }); } } return(new ResultViewModel { NoError = false, Message1 = "ERROR_OCCURD_RETRY_LATER" }); }