public static bool EmailToAdvisor(string username, AdvisorModel advisor) { var document = PrintingHelper.PrintCappReport(username); if (document == null) return false; var email = new MailMessage("*****@*****.**", advisor.Email) { Subject = "CAPPamari - Please review " + username + "'s CAPP report", Body = "Dear " + advisor.Name + ",\n" + "\n" + "Please review my latest plan for fulfulling my graduation requirements.\n" + "\n" + "Sincerely,\n" + username + "\n" + "--\n" + HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) }; using (var pdfStream = new MemoryStream()) { document.SaveToStream(pdfStream); pdfStream.Position = 0; var attachment = new Attachment(pdfStream, new ContentType(MediaTypeNames.Application.Pdf)); attachment.ContentDisposition.FileName = "CAPP Report.pdf"; email.Attachments.Add(attachment); try { var smtpServer = new SmtpClient("localhost"); smtpServer.Send(email); } catch { return false; } return true; } }
/// <summary> /// Add an advisor to a user /// </summary> /// <param name="username">Username of user to add an advisor to</param> /// <param name="newAdvisor">AdvisorModel of advisor to add to the user</param> /// <returns>Success status of advisor add</returns> public static bool AddAdvisor(string username, AdvisorModel newAdvisor) { var advisorId = EntitiesHelper.GetAdvisorId(newAdvisor.Name, newAdvisor.Email); if (advisorId == -1) { advisorId = EntitiesHelper.AddAdvisor(newAdvisor.Name, newAdvisor.Email); } return EntitiesHelper.AssociateAdvisorAndUser(username, advisorId); }
/// <summary> /// Update an advisor for a user /// </summary> /// <param name="advisor">AdvisorModel containing data to update into the advisor</param> /// <returns>Success status of the update</returns> public static bool UpdateAdvisor(AdvisorModel advisor) { return EntitiesHelper.UpdateAdvisor(advisor.Name, advisor.Email); }
/// <summary> /// Remove an advisor from the user /// </summary> /// <param name="username">Username of the user to remove the advisor from</param> /// <param name="oldAdvisor">AdvisorModel of advisor to remove from the user</param> /// <returns>Success status of the addvisor remove</returns> public static bool RemoveAdvisor(string username, AdvisorModel oldAdvisor) { var advisorId = EntitiesHelper.GetAdvisorId(oldAdvisor.Name, oldAdvisor.Email); return advisorId != -1 && EntitiesHelper.DisassociateAdvisorAndUser(username, advisorId); }