public async Task <ActionResult> GenerateCode(OutcomingMailboxViewModel model) { log.Info(Request.Url); log.Info(HttpContext == null); log.Info("GenerateCode"); var companyList = new List <SelectListItem>(); companyList.Add(new SelectListItem() { Text = "Kallpa Generación", Value = "Kallpa Generación" }); companyList.Add(new SelectListItem() { Text = "Cerro del Aguila", Value = "Cerro del Aguila" }); companyList.Add(new SelectListItem() { Text = "Samay I", Value = "Samay" }); companyList.Add(new SelectListItem() { Text = "Hidro Chilia", Value = "Hidro Chilia" }); ViewBag.CompanyList = new SelectList(companyList, "Value", "Text"); var departmentList = new List <SelectListItem>(); departmentList.Add(new SelectListItem() { Text = "Todos", Value = "Todos" }); departmentList.Add(new SelectListItem() { Text = "Administración", Value = "Administración" }); departmentList.Add(new SelectListItem() { Text = "Contraloría", Value = "Contraloría" }); departmentList.Add(new SelectListItem() { Text = "Relaciones Comunitarias", Value = "Relaciones Comunitarias" }); ViewBag.DepartmentList = new SelectList(departmentList, "Value", "Text"); var ccMail = new List <string>(); try { var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); using (var clientContext = spContext.CreateUserClientContextForSPHost()) { if (clientContext != null) { var spGroup = clientContext.Web.SiteGroups.GetByName("Correspondencia Saliente Adm"); clientContext.Load(spGroup, gr => gr.Users); clientContext.ExecuteQuery(); foreach (var spUser in spGroup.Users) { if (!string.IsNullOrEmpty(spUser.Email)) { ccMail.Add(spUser.Email); } } } } var tmpAssgnTo = JsonConvert.DeserializeObject <List <Models.PeoplePickerUser> >(model.DBModel.RequestedByLogin); model.DBModel.RequestedByLogin = tmpAssgnTo[0].Login; model.DBModel.RequestedByName = tmpAssgnTo[0].Name; model.DBModel.RequestedByEmail = tmpAssgnTo[0].Email; model.DBModel.DocumentCode = await helper.GetDocumentCode(model.DBModel.CompanyName, model.DBModel.DepartmentName, DateTime.Today.Year); if (string.IsNullOrEmpty(model.DBModel.DocumentCode)) { model.WarningMessage = "No se encuentra registrado un correlativo. Por favor, contacte al administrador"; return(View(model)); } var spHelper = new SPHelper(); model.DBModel.DocumentFolder = spHelper.CreateSPFolder(spContext, "CorSal", model.DBModel.DocumentCode); model.DBModel.RequestDate = DateTime.Now; model.DBModel.SentDate = new DateTime(1900, 1, 1); model.DBModel.DeliveryExpectedDate = new DateTime(1900, 1, 1); model.DBModel.DeliveryDate = new DateTime(1900, 1, 1); model.DBModel.RequestStatus = "Generado"; var tmpSave = await helper.PostOutMailbox(model.DBModel); var tmpModel = JsonConvert.DeserializeObject <string>(tmpSave); model.DBModel.DocumentId = Convert.ToInt32(tmpModel); var strBody = string.Format("<p>Estimado <b>{0}</b>,</p><p>Se ha generado el código <b>{1}</b> de <b>Correspondencia Saliente</b> en la Intranet.<br/></p><p>Atentamente,<br/></p><p><b>Intranet IC Power</b></p>", model.DBModel.RequestedByName, model.DBModel.DocumentCode, model.DBModel.DocumentTitle, model.DBModel.CompanyName); new Utils.EmailHelper().SendEmail("*****@*****.**", model.DBModel.RequestedByEmail, ccMail.ToArray(), "Intranet - " + model.DBModel.DocumentCode, strBody); model.ConfirmMessage = string.Format("Se ha generado el código: <b>{0}</b>.", model.DBModel.DocumentCode); } catch (Exception ex) { log.Error(ex.ToString()); } return(View(model)); }
public async Task <ActionResult> NewInbox(NewInboxViewModel model) { var companyList = new List <SelectListItem>(); companyList.Add(new SelectListItem() { Text = "Kallpa Generación", Value = "CE Kallpa Generación" }); companyList.Add(new SelectListItem() { Text = "Cerro del Aguila", Value = "CE Cerro del Aguila" }); companyList.Add(new SelectListItem() { Text = "Samay I", Value = "CE Samay" }); companyList.Add(new SelectListItem() { Text = "Hidro Chilia", Value = "CE Hidro Chilia" }); ViewBag.CompanyList = new SelectList(companyList, "Value", "Text"); var departmentList = new List <SelectListItem>(); departmentList.Add(new SelectListItem() { Text = "Todos", Value = "Todos" }); departmentList.Add(new SelectListItem() { Text = "Administración", Value = "Administración" }); departmentList.Add(new SelectListItem() { Text = "Contraloría", Value = "Contraloría" }); departmentList.Add(new SelectListItem() { Text = "Relaciones Comunitarias", Value = "Relaciones Comunitarias" }); ViewBag.DepartmentList = new SelectList(departmentList, "Value", "Text"); var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); using (var clientContext = spContext.CreateUserClientContextForSPHost()) { if (clientContext != null) { var spUser = clientContext.Web.CurrentUser; clientContext.Load(spUser, user => user.Title, user => user.LoginName, user => user.Email); clientContext.ExecuteQuery(); model.DBModel.AssignedByLogin = spUser.LoginName; model.DBModel.AssignedByName = spUser.Title; } } try { model.DBModel.DocumentCode = await helper.GetDocumentCode(model.DBModel.CompanyName, model.DBModel.DepartmentName, DateTime.Today.Year); if (string.IsNullOrEmpty(model.DBModel.DocumentCode)) { model.WarningMessage = "No se encuentra registrado un correlativo. Por favor, contacte al administrador"; return(View(model)); } var tmpAssgnTo = JsonConvert.DeserializeObject <List <Models.PeoplePickerUser> >(model.DBModel.AssignedToControl); model.DBModel.AssignedToLogin = tmpAssgnTo[0].Login; model.DBModel.AssignedToName = tmpAssgnTo[0].Name; var ccList = new List <string>(); var tmpCCLoginStr = string.Empty; var tmpCCNameStr = string.Empty; if (!string.IsNullOrEmpty(model.DBModel.AssignedToCCControl)) { var tmpAssgnToCC = JsonConvert.DeserializeObject <List <Models.PeoplePickerUser> >(model.DBModel.AssignedToCCControl); for (var i = 0; i < tmpAssgnToCC.Count; i++) { ccList.Add(tmpAssgnToCC[i].Email); tmpCCLoginStr += tmpAssgnToCC[i].Login + "/"; tmpCCNameStr += tmpAssgnToCC[i].Name + ", "; } } model.DBModel.AssignedToCCLogin = tmpCCLoginStr; model.DBModel.AssignedToCCName = tmpCCNameStr; var spHelper = new SPHelper(); var spFolder = spHelper.CreateSPFolder(spContext, "CorEnt", model.DBModel.DocumentCode); var sbAttMail = new System.Text.StringBuilder(); var sbAttModel = new System.Text.StringBuilder(); var j = 1; foreach (var anAttachment in model.Attachments) { var tmpUrl = spHelper.UploadSPFile(spContext, anAttachment, spFolder, model.DBModel.SiteUrl, "ATT" + j.ToString() + "-"); sbAttModel.AppendFormat("{0};", tmpUrl); sbAttMail.AppendFormat("- <a href='{0}'>{1}</a><br/>", tmpUrl, tmpUrl.Substring(tmpUrl.LastIndexOf("/") + 1)); j++; } model.DBModel.Attachment1Url = sbAttModel.ToString(); model.DBModel.DocumentDate = DateTime.Now; model.DBModel.DocumentStatus = "Asignado"; model.DBModel.FirstReminderDate = DateTime.Today; model.DBModel.SecondReminderDate = DateTime.Today; model.DBModel.ResponseDate = DateTime.Today.AddDays(3); model.DBModel.AssignmentDate = DateTime.Now; var tmpSave = await helper.PostInMailbox(model.DBModel, string.Empty); var strBody = string.Format("<p>Estimado <b>{0}</b>,</p><p>Se le ha asignado el documento <b>{1}</b> de <b>Correspondencia Entrante</b> en la Intranet.<br/></p><p>Para ver el documento escaneado haga clic en los siguientes enlaces:<br/>{2} <br/>Para ingresar al portal haga <a href='https://icpower.sharepoint.com'>clic aquí</a></p><p>Atentamente,<br/></p><p><b>Intranet IC Power</b></p>", model.DBModel.AssignedToName, model.DBModel.DocumentSubject, sbAttMail.ToString()); new Utils.EmailHelper().SendEmail("*****@*****.**", tmpAssgnTo[0].Email, ccList.ToArray(), "Intranet - " + model.DBModel.DocumentCode + " - " + model.DBModel.DocumentSubject, strBody); model.ConfirmMessage = "Se ha guardado el documento " + model.DBModel.DocumentCode + ". Para continuar haga clic en Cerrar."; } catch (Exception ex) { log.Error("NewInbox - " + ex.ToString()); model.ErrorMessage = "Ocurrió un error al guardar su información. Por favor cierre la ventana e intente de nuevo."; } return(View(model)); }