public async Task <BaseResponse> SaveFeedback(FeedbackRequest feedbackRequest) { try { baseResponse = new BaseResponse(); using (FacepinpointDBEntities db = new FacepinpointDBEntities()) { Feedback feedback = new FacePinPoint.Repository.Feedback(); feedback.Email = feedbackRequest.Email; feedback.Message = feedbackRequest.Message; feedback.CreatedDate = DateTime.Now; db.Feedbacks.Add(feedback); await db.SaveChangesAsync(); //var templateResponse = db.Database.SqlQuery<TemplateDetail>("SELECT \"TemplateId\", \"TemplateName\", \"Subject\", \"Template\", \"Active\" FROM public.\"EmailTemplates\" where \"TemplateName\"= 'Subscription';").FirstOrDefault(); // var templateResponse = await db.EmailTemplates.Select(x => new TemplateDetail { Active = x.Active, Subject = x.Subject, Template = x.Template, TemplateId = x.TemplateId, TemplateName = x.TemplateName }).Where(x => x.TemplateName == "FeedBack").FirstOrDefaultAsync(); var templateResponse = await db.Database.SqlQuery <FacePinPoint.Entities.Response.TemplateDetail>("SELECT \"TemplateId\", \"TemplateName\", \"Subject\", \"public\".\"fn_GetUserEmail\"('FeedBack','" + feedbackRequest.Email + "') AS \"Template\", \"Active\" from \"public\".\"EmailTemplates\" where \"TemplateName\"='FeedBack'").FirstOrDefaultAsync(); mailContent = new MailContent(); mailContent.ToEmail = feedbackRequest.Email; mailContent.MsgSubject = templateResponse.Subject; mailContent.MsgBody = templateResponse.Template; // Email sender EmailSender.MailSender(mailContent); } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); baseResponse.Success = false; baseResponse.Message = CustomErrorMessages.INTERNAL_ERROR; } return(baseResponse); }
public async Task <BaseResponse> SaveSubscribe(EmailSubscriptionRequest emailSubscriptionRequest) { try { baseResponse = new BaseResponse(); var subscribeEmailExistsResponse = await SubscribeEmailExists(emailSubscriptionRequest.Email); if (!subscribeEmailExistsResponse.IsEmailExists) { using (FacepinpointDBEntities db = new FacepinpointDBEntities()) { Subscription subscription = new Subscription(); subscription.Email = emailSubscriptionRequest.Email; subscription.SubscriptionDate = DateTime.Now; subscription.Active = "Y"; db.Subscriptions.Add(subscription); await db.SaveChangesAsync(); //var templateResponse = db.Database.SqlQuery<TemplateDetail>("SELECT \"TemplateId\", \"TemplateName\", \"Subject\", \"Template\", \"Active\" FROM public.\"EmailTemplates\" where \"TemplateName\"= 'Subscription';").FirstOrDefault(); //var templateResponse = await db.EmailTemplates.Select(x => new TemplateDetail { Active = x.Active, Subject = x.Subject, Template = x.Template, TemplateId = x.TemplateId, TemplateName = x.TemplateName }).Where(x => x.TemplateName == "Subscription").FirstOrDefaultAsync(); var templateResponse = await db.Database.SqlQuery <FacePinPoint.Entities.Response.TemplateDetail>("SELECT \"TemplateId\", \"TemplateName\", \"Subject\", \"public\".\"fn_GetUserEmail\"('Subscription','" + emailSubscriptionRequest.Email + "') AS \"Template\", \"Active\" from \"public\".\"EmailTemplates\" where \"TemplateName\"='Subscription'").FirstOrDefaultAsync(); mailContent = new MailContent(); mailContent.ToEmail = emailSubscriptionRequest.Email; mailContent.MsgSubject = templateResponse.Subject; mailContent.MsgBody = templateResponse.Template; // Email sender EmailSender.MailSender(mailContent); } } else { baseResponse.Success = false; } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); baseResponse.Success = false; baseResponse.Message = CustomErrorMessages.INTERNAL_ERROR; } return(baseResponse); }