public void SendEmail(RequistionDTO requistion, string userId) { DateTime createdOn = DateTime.Now; StringBuilder sb = new StringBuilder(); string strNewPath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["RequistionEmail"]); using (StreamReader sr = new StreamReader(strNewPath)) { while (!sr.EndOfStream) { sb.Append(sr.ReadLine()); } } string body = sb.ToString().Replace("#REQUISTIONNUMBER#", requistion.RequistionNumber); body = body.Replace("#DESCRIPTION#", requistion.Description); body = body.Replace("#CREATEDBY#", userId); body = body.Replace("#CREATEDON#", Convert.ToString(createdOn)); Helpers.Email email = new Helpers.Email(); email.MailBodyHtml = body; email.MailToAddress = ConfigurationManager.AppSettings["administrator-email"]; email.MailFromAddress = ConfigurationManager.AppSettings["EmailAddressFrom"]; email.Subject = ConfigurationManager.AppSettings["requistion_email_subject"]; email.SendMail(); logger.Debug("Email sent"); }
/// <summary> /// Saves a new Requistion or updates an already existing Requistion. /// </summary> /// <param name="Requistion">Requistion to be saved or updated.</param> /// <param name="RequistionId">RequistionId of the Requistion creating or updating</param> /// <returns>RequistionId</returns> public long SaveRequistion(RequistionDTO requistionDTO, string userId) { long requistionId = 0; if (requistionDTO.RequistionId == 0) { var requistion = new Requistion() { RequistionId = requistionDTO.RequistionId, StatusId = requistionDTO.StatusId, BranchId = requistionDTO.BranchId, Response = requistionDTO.Response, Amount = requistionDTO.Amount, Description = requistionDTO.Description, ApprovedById = requistionDTO.ApprovedById, RequistionNumber = requistionDTO.RequistionNumber, CreatedOn = DateTime.Now, TimeStamp = DateTime.Now, CreatedBy = userId, Deleted = false, }; this.UnitOfWork.Get <Requistion>().AddNew(requistion); this.UnitOfWork.SaveChanges(); requistionId = requistion.RequistionId; return(requistionId); } else { var result = this.UnitOfWork.Get <Requistion>().AsQueryable() .FirstOrDefault(e => e.RequistionId == requistionDTO.RequistionId); if (result != null) { result.RequistionId = requistionDTO.RequistionId; result.StatusId = requistionDTO.StatusId; result.ApprovedById = requistionDTO.ApprovedById; result.Amount = requistionDTO.Amount; result.UpdatedBy = userId; result.Response = requistionDTO.Response; result.BranchId = requistionDTO.BranchId; result.RequistionNumber = requistionDTO.RequistionNumber; result.TimeStamp = DateTime.Now; result.Deleted = requistionDTO.Deleted; result.DeletedBy = requistionDTO.DeletedBy; result.DeletedOn = requistionDTO.DeletedOn; this.UnitOfWork.Get <Requistion>().Update(result); this.UnitOfWork.SaveChanges(); } return(requistionDTO.RequistionId); } }