/// <summary> /// /// </summary> /// <param name="guid"></param> /// <returns></returns> public bool SendThankUForSocialSignUpEmail(Guid guid) { var user = bringlyEntities.tblUsers.Where(usr => usr.UserGuid == guid && usr.IsDeleted == false).FirstOrDefault(); if (user == null || user.EmailAddress == null) { return(false); } string currentDomainName = string.Empty; Utilities.Helper.UtilityHelper.GetHostedDomainName(out currentDomainName); string imgSrc = CommonDomainLogic.GetCurrentDomain + CommonDomainLogic.GetImagePath(ImageType.User, "bringlylogoemail.png"); EmailDomain emailDomain = new EmailDomain(); emailDomain.EmailTo = user.EmailAddress; emailDomain.EmailFrom = ConfigurationManager.AppSettings["EmailFrom"]; tblEmailTemplate Template = bringlyEntities.tblEmailTemplates.Where(x => x.TemplateType == "ThankYouSocialSignUp").FirstOrDefault(); if (Template == null) { return(false); } emailDomain.EmailSubject = Template.Subject; emailDomain.EmailBody = Template.Body.Replace("{ToName}", user.FullName).Replace("{hostUrl}", currentDomainName).Replace("{logoUrl}", currentDomainName + "/Templates/images/bringlylogoemail.png"); string emailSendResult = EmailSender.sendEmail(emailDomain); if (!string.IsNullOrEmpty(emailSendResult)) { ErrorLog.LogError(emailSendResult, "send email Error"); return(false); } return(true); }
/// <summary> /// /// </summary> /// <param name="LatestPage"></param> /// <returns></returns> public MyEmail GetSentEmail(int LatestPage = 0) { MyEmail Email = new MyEmail(); Email.PageSize = PageSize; Email.CurrentPage = LatestPage > 0 ? LatestPage : CurrentPage; Email.SortBy = SortBy; string restaurantimagepath = string.Empty; var restaurant = bringlyEntities.tblRestaurants.Where(x => x.CreatedByGuid == x.tblUser.UserGuid).FirstOrDefault(); if (restaurant != null) { restaurantimagepath = CommonDomainLogic.GetCurrentDomain + CommonDomainLogic.GetImagePath(ImageType.Restaurant, restaurant.RestaurantImage); } Email.Emails = bringlyEntities.tblEmails.Where(x => x.FK_CreatedByGuid == UserVariables.LoggedInUserGuid && x.IsDeleted == false && x.Sent == true). Select(em => new Email { EmailGuid = em.EmailGuid, TemplateGuid = em.FK_TemplateGuid, Subject = em.Subject, Body = em.Body, EmailFrom = em.EmailFrom, DateCreated = em.DateCreated , FromName = em.tblUser.FullName, ToName = em.tblEmailToes.Where(x => x.FK_UserGuid == x.tblUser.UserGuid).ToList().FirstOrDefault().tblUser.FullName , EmailToList = em.tblEmailToes.Where(x => x.FK_UserGuid == x.tblUser.UserGuid).ToList().Select(t => new EmailTo { UserGuid = t.FK_UserGuid, Name = t.tblUser.FullName }).ToList() , UserImage = em.tblUser.ImageName }).OrderByDescending(x => x.DateCreated).ToList(); Email.Emails.ForEach(z => z.RestaurantImage = restaurantimagepath); Email.UnReadCount = bringlyEntities.tblEmailToes.Where(x => x.FK_UserGuid == UserVariables.LoggedInUserGuid && x.IsDeleted == false && x.tblEmail.Sent == true && x.Read == false && x.FK_EmailGuid == x.tblEmail.EmailGuid) .ToList().Count; Email.TotalRecords = Email.Emails.Count; int Skip = 0; int Take = PageSize; if (Email.CurrentPage == 1) { Skip = 0; } else { Skip = ((Email.CurrentPage * Email.PageSize) - Email.PageSize); } if (Email.TotalRecords == 0 && Skip > 0) { Skip = Skip - 1; } Email.Emails = Email.Emails.Skip(Skip).Take(Take).ToList(); return(Email); }
/// <summary> /// /// </summary> /// <param name="Request"></param> /// <returns></returns> public string UploadMenuItemImage(HttpRequestBase Request) { tblUser user = bringlyEntities.tblUsers.Where(x => x.UserGuid == UserVariables.LoggedInUserGuid).FirstOrDefault(); string imageName = ""; string imageLocation = ""; if (Request.Files.Count > 0) { Items item = new Items(); for (int i = 0; i < Request.Files.Count; i++) { imageName = Path.GetFileName("Item_" + Guid.NewGuid() + Path.GetExtension(Request.Files[i].FileName)); imageLocation = CommonDomainLogic.GetImagePath(Domain.Enums.ImageType.Item, imageName); Request.Files[i].SaveAs(HttpContext.Current.Server.MapPath(imageLocation)); } item.ItemImage = imageName; return(imageLocation); } else { return(imageLocation); } }
/// <summary> /// /// </summary> /// <param name="LatestPage"></param> /// <param name="searchQuery"></param> /// <param name="sortBy"></param> /// <returns></returns> public MyEmail GetInboxEmail(int LatestPage = 0, string searchQuery = "", string sortBy = "lto") { MyEmail Email = new MyEmail(); Email.PageSize = PageSize; Email.CurrentPage = LatestPage > 0 ? LatestPage : CurrentPage;; //ViewBag.CurrentPage Email.SortBy = SortBy; string restaurantimagepath = string.Empty; var restaurant = bringlyEntities.tblRestaurants.Where(x => x.CreatedByGuid == x.tblUser.UserGuid).FirstOrDefault(); var temp = bringlyEntities.tblBusinesses.Where(x => x.FK_CreatedByGuid == x.tblUser.UserGuid).FirstOrDefault(); if (restaurant != null) { restaurantimagepath = CommonDomainLogic.GetCurrentDomain + CommonDomainLogic.GetImagePath(ImageType.Restaurant, restaurant.RestaurantImage); } else { restaurantimagepath = CommonDomainLogic.GetCurrentDomain + CommonDomainLogic.GetImagePath(null, null); } var data = bringlyEntities.tblEmailToes .Where(x => x.FK_EmailGuid == x.tblEmail.EmailGuid && x.IsDeleted == false && x.FK_UserGuid == UserVariables.LoggedInUserGuid); if (!string.IsNullOrEmpty(searchQuery)) { data = data.Where(x => x.tblEmail.Subject.Contains(searchQuery)); } if (sortBy != null && sortBy.Equals("otl")) { Email.Emails = data.Select(em => new Email { EmailGuid = em.tblEmail.EmailGuid, TemplateGuid = em.tblEmail.FK_TemplateGuid, Subject = em.tblEmail.Subject, Body = em.tblEmail.Body, EmailFrom = em.tblEmail.EmailFrom, DateCreated = em.tblEmail.DateCreated, FromName = bringlyEntities.tblUsers.Where(zx => zx.UserGuid == em.tblEmail.FK_CreatedByGuid).FirstOrDefault().FullName, Read = em.Read, ToName = em.tblUser.FullName, UserImage = bringlyEntities.tblUsers.Where(zx => zx.UserGuid == em.tblEmail.FK_CreatedByGuid).FirstOrDefault().ImageName }) .OrderBy(x => x.DateCreated) .ToList() .OrderBy(x => x.Read == false) .ToList(); } else { Email.Emails = data .Select(em => new Email { EmailGuid = em.tblEmail.EmailGuid, TemplateGuid = em.tblEmail.FK_TemplateGuid, Subject = em.tblEmail.Subject, Body = em.tblEmail.Body, EmailFrom = em.tblEmail.EmailFrom, DateCreated = em.tblEmail.DateCreated, FromName = bringlyEntities.tblUsers.Where(zx => zx.UserGuid == em.tblEmail.FK_CreatedByGuid).FirstOrDefault().FullName, Read = em.Read, ToName = em.tblUser.FullName, UserImage = bringlyEntities.tblUsers.Where(zx => zx.UserGuid == em.tblEmail.FK_CreatedByGuid).FirstOrDefault().ImageName }) .OrderByDescending(x => x.DateCreated) .ToList() .OrderByDescending(x => x.Read == false) .ToList(); } Email.Emails.ForEach(z => z.RestaurantImage = restaurantimagepath); Email.UnReadCount = bringlyEntities.tblEmailToes.Where(x => x.FK_UserGuid == UserVariables.LoggedInUserGuid && x.IsDeleted == false && x.tblEmail.Sent == true && x.Read == false && x.FK_EmailGuid == x.tblEmail.EmailGuid) .ToList().Count; Email.TotalRecords = Email.Emails.Count; int Skip = 0; int Take = PageSize; if (Email.CurrentPage == 1) { Skip = 0; } else { Skip = ((Email.CurrentPage * Email.PageSize) - Email.PageSize); } Email.Emails = Email.Emails.Skip(Skip).Take(Take).ToList(); return(Email); }
/// <summary> /// /// </summary> /// <param name="ComposeEmail"></param> /// <returns></returns> public bool SendEmail(ComposeEmail ComposeEmail) { EmailDomain EmailDomain = new EmailDomain(); tblUser userfrom = bringlyEntities.tblUsers.Where(x => x.UserGuid == UserVariables.LoggedInUserGuid).ToList().FirstOrDefault(); tblEmailTemplate template = new tblEmailTemplate(); BusinessObject tblBusiness = new BusinessObject(); string image = "<img src = " + CommonDomainLogic.GetCurrentDomain + CommonDomainLogic.GetImagePath(ImageType.Default, "") + ">"; string UserImageName = userfrom.ImageName; int count = 0; if (ComposeEmail.EmailToGuid != null && ComposeEmail.EmailToGuid.Count() > 0) { foreach (string usertoguid in ComposeEmail.EmailToGuid) { tblUser userto = bringlyEntities.tblUsers.Where(x => x.UserGuid == new Guid(usertoguid)).ToList().FirstOrDefault(); EmailDomain.EmailTo = userto.EmailAddress; template = !string.IsNullOrEmpty(ComposeEmail.EmailMessage.TemplateType) ? bringlyEntities.tblEmailTemplates .Where(x => x.TemplateType == ComposeEmail.EmailMessage.TemplateType).ToList().FirstOrDefault() : new tblEmailTemplate(); if (template != null && template.TemplateGuid != null && template.TemplateGuid != Guid.Empty) { EmailDomain.EmailFrom = userfrom.EmailAddress; EmailDomain.EmailSubject = ComposeEmail.EmailMessage.Subject; if (!ComposeEmail.Isemailreplyorforward) { tblBusiness = bringlyEntities.tblBusinesses.Where(x => x.FK_CreatedByGuid == UserVariables.LoggedInUserGuid). Select(s => new BusinessObject { BusinessImage = s.BusinessImage, BusinessName = s.BusinessName }).ToList().FirstOrDefault(); EmailDomain.EmailBody = template.Body; EmailDomain.EmailBody = EmailDomain.EmailBody.Replace("{ToName}", userto.FullName).Replace("{Description}", ComposeEmail.EmailMessage.Body) .Replace("{FromName}", userfrom.FullName); } else { EmailDomain.EmailBody = ComposeEmail.EmailMessage.Body; } string emailSendResult = EmailSender.sendEmail(EmailDomain); if (!string.IsNullOrEmpty(emailSendResult)) { ErrorLog.LogError(emailSendResult, "send email Error"); } tblEmail tblEmail = new tblEmail(); tblEmail.EmailGuid = Guid.NewGuid(); tblEmail.EmailFrom = EmailDomain.EmailFrom; tblEmail.Subject = EmailDomain.EmailSubject; tblEmail.Body = EmailDomain.EmailBody; tblEmail.Sent = (emailSendResult == "") ? true : false; tblEmail.FK_TemplateGuid = template.TemplateGuid; tblEmail.DateCreated = DateTime.Now; tblEmail.FK_CreatedByGuid = UserVariables.LoggedInUserGuid; bringlyEntities.tblEmails.Add(tblEmail); if (tblEmail.Sent) { tblEmailTo tblEmailTo = new tblEmailTo(); tblEmailTo.EmailToGuid = Guid.NewGuid(); tblEmailTo.FK_EmailGuid = tblEmail.EmailGuid; tblEmailTo.EmailTo = EmailDomain.EmailTo; tblEmailTo.FK_UserGuid = new Guid(usertoguid);// new Guid(usertoguid); bringlyEntities.tblEmailToes.Add(tblEmailTo); } bringlyEntities.SaveChanges(); count = count + ((emailSendResult == "") ? 0 : 1); } } } else { count++; } if (count > 0) { return(false); } else { return(true); } }