public async Task <RegisterViewModel> GetUserByEmailId(string emailId, string appType) { RegisterViewModel userModel = null; try { await Task.Run(() => { using (var db = new SocialCRMEntities()) { var user = db.AspNetUsers.Where(x => string.Compare(x.Email, emailId) == 0).FirstOrDefault(); if (user != null) { userModel = new RegisterViewModel { Name = user.Name, Email = user.Email, ImageUrl = user.ProfileImage, UserId = user.Id, SignHTML = user.SignHTML }; userModel.UserRoles = user.AspNetRoles.Where(x => x.Name.StartsWith(appType)).Select(x => x.Name).ToList(); userModel.AppType = appType; } db.Dispose(); } }); return(userModel); } catch (Exception ex) { return(userModel); } }
public async Task <bool> DeleteUserReference(int id) { bool result = false; try { await Task.Run(() => { using (SocialCRMEntities db = new SocialCRMEntities()) { var list = db.MediaNews.Where(x => x.CreatedBy.HasValue ? (x.CreatedBy.Value == id) : false).ToList(); foreach (var news in list) { news.CreatedBy = null; db.MediaNews.Attach(news); db.Entry(news).State = EntityState.Modified; db.SaveChanges(); } result = true; } }); } catch (Exception ex) { result = false; } return(result); }
public async Task <string> EmailPdfReport(string fileName, string fileContent, string contentType, string applicationPath) { string result = ""; try { await Task.Run(() => { using (SocialCRMEntities db = new SocialCRMEntities()) { List <Attachment> attachmentCollection = new List <Attachment>(); var pdfBinary = Convert.FromBase64String(fileContent.Split(',')[1]); System.Web.Mvc.FileContentResult fileContentResult = new System.Web.Mvc.FileContentResult(pdfBinary, "application/octet-stream"); MemoryStream ms = new MemoryStream(fileContentResult.FileContents); ContentType ct = new ContentType(fileContentResult.ContentType); Attachment attachment = new Attachment(ms, ct); attachment.Name = fileName; attachmentCollection.Add(attachment); List <string> emailIds = db.Emails.Where(x => x.EmailRights.Where(y => y.EmailRightName == "Consolidated").Count() > 0).Select(e => e.EmailId).Distinct().ToList <string>(); EmailSender.SendEmailInThread(emailIds, null, "KE - Automated Communications System Report", "Please find the attached Automated Communications System Report", attachmentCollection); result = "success"; } }); } catch (Exception ex) { throw ex; } return(result); }
public async Task <EmailModel> GeEmailList(int appType, int pageNumber) { EmailModel result = new EmailModel(); result.EmailList = new List <MediaEmailModel>(); int pageSize = 10; pageNumber = pageNumber * pageSize; try { using (SocialCRMEntities db = new SocialCRMEntities()) { var emails = db.Emails.ToList();//.Skip(pageNumber).Take(pageSize).ToList(); foreach (var email in emails) { MediaEmailModel model = new MediaEmailModel(); model.Id = email.Id; model.EmailId = email.EmailId; model.RightsArray = email.EmailRights.ToList().Select(x => x.Id).ToList <int>(); model.TvRightCss = model.RadioRightCss = model.PrintRightCss = model.ConsolidatedRightCss = "tick_grey"; foreach (var right in email.EmailRights) { if (right.Id == 1) { model.TvRightCss = "tick_green"; } else if (right.Id == 2) { model.RadioRightCss = "tick_green"; } else if (right.Id == 3) { model.PrintRightCss = "tick_green"; } else if (right.Id == 4) { model.ConsolidatedRightCss = "tick_green"; } } result.EmailList.Add(model); } result.RightsList = new List <SelectItemList>(); db.EmailRights.ToList().ForEach(delegate(EmailRight obj) { result.RightsList.Add(new SelectItemList() { Value = obj.Id, Text = obj.EmailRightName }); }); } } catch (Exception ex) { result = null; } return(result); }
public async Task <bool> SaveUser(UserSaveModel model, int userId) { bool result = false; try { using (SocialCRMEntities db = new SocialCRMEntities()) { var form = new AspNetUser(); if (model.Id > 0) { form = db.AspNetUsers.Find(model.Id); } else { } if (model.Id > 0) { //form.Categories.Clear(); //foreach (var item in categories) //{ // form.Categories.Add(db.Categories.Find(item)); //} //db.MediaNews.Attach(form); //db.Entry(form).State = EntityState.Modified; } else { //foreach (var item in categories) //{ // form.Categories.Add(db.Categories.Find(item)); //} //db.MediaNews.Add(form); } db.SaveChanges(); result = true; } } catch (Exception ex) { result = false; } return(result); }
public async Task <bool> UpdatePersonalProfile(PersonalProfileModel model) { var success = false; await Task.Run(() => { using (var db = new SocialCRMEntities()) { var userProfile = db.AspNetUsers.Where(z => z.Email == model.Email).FirstOrDefault(); userProfile.Name = model.Name; userProfile.ProfileImage = model.ProfileUrl; userProfile.SignHTML = model.SignHtml; db.SaveChanges(); db.Dispose(); } }); return(success); }
public async Task <List <MediaFormListModel> > GetMediaReportDrillDown(MediaNewsReportFilterSearchModel model) { List <MediaFormListModel> result = new List <MediaFormListModel>(); try { await Task.Run(() => { using (SocialCRMEntities db = new SocialCRMEntities()) { result = db.GetMediaReportDrillDown(model.userId, model.mediaTypeId, model.newsTypeIds, model.channelIds, model.categoryIds, model.relavanceIds, model.fromDate, model.toDate, model.script, model.isKEActivity, model.reportType, model.filterType, model.xAxis1, model.xAxis2, model.pageNumber, model.pageSize).Select(x => new MediaFormListModel() { Id = x.Id, MediaType = x.MediaType, NewsType = x.NewsType, Channel = x.Channel, Sentiment = x.Sentiment, NewsRelevance = x.NewsRelation, TransmissionDate = x.NewsDate.ToString(), TransmissionTime = x.NewsTime.ToString(), NoiseIndex = Convert.ToDecimal(x.NoiseIndex), CreatedBy = x.CreatedBy, PrValue = x.ParValue, CreatedDate = x.CreatedDate.ToString(), Script = x.Script, ClippingAttachment = new MediaAttachmentModel() { FileName = x.FileName, ContentType = x.FileType } }).ToList(); } }); } catch (Exception ex) { result = null; } return(result); }
public async Task <bool> SaveMediaEmail(MediaEmailSaveModel model) { bool result = false; try { await Task.Run(async() => { using (var context = new SocialCRMEntities()) { if (model.Id > 0) { await DeleteMediaEmail(model.Id.Value); } if (context.Emails.Where(x => x.EmailId == model.EmailId).Count() <= 0) { Email emailObj = new Email(); emailObj.EmailId = model.EmailId; if (!String.IsNullOrEmpty(model.Rights)) { var rightIds = model.Rights.Split(',').Select(x => Convert.ToInt32(x)).ToArray(); foreach (var item in rightIds) { emailObj.EmailRights.Add(context.EmailRights.Find(item)); } } context.Emails.Add(emailObj); context.SaveChanges(); result = true; } } }); } catch (Exception ex) { result = false; } return(result); }
public async Task <bool> DeleteMediaEmail(int id) { bool result = false; try { using (SocialCRMEntities db = new SocialCRMEntities()) { var email = db.Emails.Find(id); if (email != null) { email.EmailRights.Clear(); db.Emails.Remove(email); db.SaveChanges(); } result = true; } } catch (Exception ex) { result = false; } return(result); }
public async Task <UserListModel> GeMediaUserList(int userId, string appType, int pageNumber) { UserListModel result = new UserListModel(); result.UserList = new List <UserModel>(); int pageSize = 5; pageNumber = pageNumber * pageSize; try { await Task.Run(() => { using (SocialCRMEntities db = new SocialCRMEntities()) { decimal[] rightsArray = { 1, 2, 3, 4 }; decimal[] rolesArray = { 2, 3, 4 }; var userList = db.AspNetUsers.ToList().Where(x => x.AspNetRoles.Where(y => rightsArray.Contains(y.Id)).Count() > 0 && x.Id != userId).OrderByDescending(y => y.Id).ToList(); result.TotalRecords = userList.Count; userList = userList.Skip(pageNumber).Take(pageSize).ToList(); foreach (var item in userList) { UserModel model = new UserModel(); model.Id = item.Id; model.Name = item.Name; model.Email = item.Email; model.ProfileUrl = item.ProfileImage; model.IsEnabled = item.EmailConfirmed; model.RightsArray = item.AspNetRoles.Select(x => x.Id).ToList <int>(); model.RightName = item.AspNetRoles.Where(x => x.Id == 1).Count() > 0 ? "Admin" : "User"; model.TvRightCss = model.RadioRightCss = model.PrintRightCss = "inactivetag"; if (model.RightName != "Admin") { foreach (var right in item.AspNetRoles) { if (right.Id == 2) { model.PrintRightCss = "printtag"; } else if (right.Id == 3) { model.RadioRightCss = "radiotag"; } else if (right.Id == 4) { model.TvRightCss = "tvtag"; } } } result.UserList.Add(model); } result.MediaTypesList = new List <SelectItemList>(); db.AspNetRoles.Where(y => rolesArray.Contains(y.Id)).ToList().ForEach(delegate(AspNetRole obj) { result.MediaTypesList.Add(new SelectItemList() { Value = obj.Id, Text = obj.Name, MediaTypeId = 0 }); }); } }); } catch (Exception ex) { result = null; } return(result); }
public async Task <EDReportModel> GetMediaReportChannelList(int userId) { EDReportModel result = new EDReportModel(); try { await Task.Run(() => { using (SocialCRMEntities db = new SocialCRMEntities()) { result.ChannelsList = new List <SelectItemList>(); db.MediaChannels.OrderBy(x => x.ChannelName).ToList().ForEach(delegate(MediaChannel obj) { result.ChannelsList.Add(new SelectItemList() { Value = obj.Id, Text = obj.ChannelName, MediaTypeId = obj.MediaTypeId }); }); result.EDReportFilterList = new List <SelectItemListFilter>(); db.EDReportFilters.ToList().ForEach(delegate(EDReportFilter obj) { result.EDReportFilterList.Add(new SelectItemListFilter() { Value = obj.ReportType, Text = obj.ChannelIds, FilterType = obj.FilterType }); }); result.SentimentList = new List <SelectItemList>(); db.Sentiments.OrderBy(x => x.Name).ToList().ForEach(delegate(Sentiment obj) { result.SentimentList.Add(new SelectItemList() { Value = obj.Id, Text = obj.Name, MediaTypeId = 0 }); }); result.NewsRelatedToList = new List <SelectItemList>(); db.NewsRelatedToes.OrderBy(x => x.Name).ToList().ForEach(delegate(NewsRelatedTo obj) { result.NewsRelatedToList.Add(new SelectItemList() { Value = obj.Id, Text = obj.Name, MediaTypeId = 0 }); }); } }); } catch (Exception ex) { result = null; } return(result); }
public async Task <string> EmailMediaMonitoringReport(EmailMonitoringReportModel model, HttpContext current) { string result = ""; try { await Task.Run(() => { using (SocialCRMEntities db = new SocialCRMEntities()) { string tvTemplate = System.IO.File.ReadAllText(current.Server.MapPath(@"~/Content/EmailTemplates/KE_1.html")); string printTemplate = System.IO.File.ReadAllText(current.Server.MapPath(@"~/Content/EmailTemplates/KE_2.html")); List <string> emailIds = new List <string>(); emailIds = db.Emails.Where(x => x.EmailRights.Where(y => y.EmailRightName == "Consolidated").Count() > 0).Select(e => e.EmailId).Distinct().ToList <string>(); if (model.isPrint) { string body = printTemplate; body = body.Replace("##TotalMediaRecords##", model.totalMediaRecords.ToString()); body = body.Replace("##TopThreeChannels##", model.top3Areas); body = body.Replace("##BottomThreeChannels##", model.bot3Areas); body = body.Replace("##TotalPRValue##", model.totalPRValue.ToString()); for (int i = 1; i < 4; i++) { string sentiment = "", positive = "", neutral = "", negative = "", total = ""; if (i <= model.totalSentimentData.Count) { sentiment = model.totalSentimentData[i - 1].RelName; positive = model.totalSentimentData[i - 1].Positive.ToString(); neutral = model.totalSentimentData[i - 1].Neutral.ToString(); negative = model.totalSentimentData[i - 1].Negative.ToString(); total = model.totalSentimentData[i - 1].TotalSent.ToString(); } body = body.Replace("##Sentiment" + i + "##", sentiment); body = body.Replace("##Positive" + i + "##", positive); body = body.Replace("##Neutral" + i + "##", neutral); body = body.Replace("##Negative" + i + "##", negative); body = body.Replace("##Total" + i + "##", total); } AlternateView av1 = AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html); var bytes = Convert.FromBase64String(model.totalSentimentImg.Split(',')[1]); LinkedResource logoPhoto = new LinkedResource(new MemoryStream(bytes), "image/jpeg"); logoPhoto.ContentId = "shiftReport1"; av1.LinkedResources.Add(logoPhoto); bytes = Convert.FromBase64String(model.keTotalChannelImg.Split(',')[1]); logoPhoto = new LinkedResource(new MemoryStream(bytes), "image/jpeg"); logoPhoto.ContentId = "shiftReport2"; av1.LinkedResources.Add(logoPhoto); bytes = Convert.FromBase64String(model.keSentimentImg.Split(',')[1]); logoPhoto = new LinkedResource(new MemoryStream(bytes), "image/jpeg"); logoPhoto.ContentId = "shiftReport3"; av1.LinkedResources.Add(logoPhoto); bytes = Convert.FromBase64String(model.activitiesImg.Split(',')[1]); logoPhoto = new LinkedResource(new MemoryStream(bytes), "image/jpeg"); logoPhoto.ContentId = "shiftReport4"; av1.LinkedResources.Add(logoPhoto); string subject = "Print Monitoring Report (" + model.date.ToString("dd MMMM yyyy") + ")"; List <Attachment> attachmentList = new List <Attachment>(); EmailSender.SendEmailInThreadWithAlternateView(emailIds, null, subject, body, attachmentList, av1); } else { string body = tvTemplate; body = body.Replace("##TotalMediaRecords##", model.totalMediaRecords.ToString()); body = body.Replace("##TopThreeChannels##", model.top3Areas); body = body.Replace("##BottomThreeChannels##", model.bot3Areas); body = body.Replace("##OnDutyAgents##", model.onDutyAgents); for (int i = 1; i < 4; i++) { string sentiment = "", positive = "", neutral = "", negative = "", total = ""; if (i <= model.totalSentimentData.Count) { sentiment = model.totalSentimentData[i - 1].RelName; positive = model.totalSentimentData[i - 1].Positive.ToString(); neutral = model.totalSentimentData[i - 1].Neutral.ToString(); negative = model.totalSentimentData[i - 1].Negative.ToString(); total = model.totalSentimentData[i - 1].TotalSent.ToString(); } body = body.Replace("##Sentiment" + i + "##", sentiment); body = body.Replace("##Positive" + i + "##", positive); body = body.Replace("##Neutral" + i + "##", neutral); body = body.Replace("##Negative" + i + "##", negative); body = body.Replace("##Total" + i + "##", total); } AlternateView av1 = AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html); var bytes = Convert.FromBase64String(model.keEvolutionImg.Split(',')[1]); LinkedResource logoPhoto = new LinkedResource(new MemoryStream(bytes), "image/jpeg"); logoPhoto.ContentId = "shiftReport1"; av1.LinkedResources.Add(logoPhoto); bytes = Convert.FromBase64String(model.totalSentimentImg.Split(',')[1]); logoPhoto = new LinkedResource(new MemoryStream(bytes), "image/jpeg"); logoPhoto.ContentId = "shiftReport2"; av1.LinkedResources.Add(logoPhoto); bytes = Convert.FromBase64String(model.keSentimentImg.Split(',')[1]); logoPhoto = new LinkedResource(new MemoryStream(bytes), "image/jpeg"); logoPhoto.ContentId = "shiftReport3"; av1.LinkedResources.Add(logoPhoto); bytes = Convert.FromBase64String(model.keCategoryImg.Split(',')[1]); logoPhoto = new LinkedResource(new MemoryStream(bytes), "image/jpeg"); logoPhoto.ContentId = "shiftReport4"; av1.LinkedResources.Add(logoPhoto); bytes = Convert.FromBase64String(model.keNIChannelImg.Split(',')[1]); logoPhoto = new LinkedResource(new MemoryStream(bytes), "image/jpeg"); logoPhoto.ContentId = "shiftReport5"; av1.LinkedResources.Add(logoPhoto); bytes = Convert.FromBase64String(model.activitiesImg.Split(',')[1]); logoPhoto = new LinkedResource(new MemoryStream(bytes), "image/jpeg"); logoPhoto.ContentId = "shiftReport6"; av1.LinkedResources.Add(logoPhoto); string subject = "Electronic & Radio Monitoring - " + model.shift + " (" + model.date.ToString("dd MMMM yyyy") + ")"; List <Attachment> attachmentList = new List <Attachment>(); EmailSender.SendEmailInThreadWithAlternateView(emailIds, null, subject, body, attachmentList, av1); } result = "success"; } }); } catch (Exception ex) { throw ex; } return(result); }
public async Task <ReportFilterModel> GetMediaReportFilters(int userId) { ReportFilterModel result = new ReportFilterModel(); try { await Task.Run(() => { using (SocialCRMEntities db = new SocialCRMEntities()) { result.MediaTypesList = new List <SelectItemList>(); db.MediaTypes.ToList().ForEach(delegate(MediaType obj) { result.MediaTypesList.Add(new SelectItemList() { Value = obj.Id, Text = obj.TypeName, MediaTypeId = obj.Id }); }); result.NewsTypeList = new List <SelectItemList>(); db.NewsTypes.OrderBy(x => x.NewsTypeName).ToList().ForEach(delegate(NewsType obj) { result.NewsTypeList.Add(new SelectItemList() { Value = obj.Id, Text = obj.NewsTypeName, MediaTypeId = obj.MediaTypeId }); }); result.ChannelsList = new List <SelectItemList>(); db.MediaChannels.OrderBy(x => x.ChannelName).ToList().ForEach(delegate(MediaChannel obj) { result.ChannelsList.Add(new SelectItemList() { Value = obj.Id, Text = obj.ChannelName, MediaTypeId = obj.MediaTypeId }); }); result.CategoriesList = new List <SelectItemList>(); db.Categories.OrderBy(x => x.CategoryName).ToList().ForEach(delegate(Category obj) { result.CategoriesList.Add(new SelectItemList() { Value = obj.Id, Text = obj.CategoryName, MediaTypeId = 0 }); }); result.NewsRelatedToList = new List <SelectItemList>(); db.NewsRelatedToes.OrderBy(x => x.Name).ToList().ForEach(delegate(NewsRelatedTo obj) { result.NewsRelatedToList.Add(new SelectItemList() { Value = obj.Id, Text = obj.Name, MediaTypeId = 0 }); }); result.SentimentList = new List <SelectItemList>(); db.Sentiments.OrderBy(x => x.Name).ToList().ForEach(delegate(Sentiment obj) { result.SentimentList.Add(new SelectItemList() { Value = obj.Id, Text = obj.Name, MediaTypeId = 0 }); }); result.AgentList = new List <SelectItemList>(); db.AspNetUsers.OrderBy(x => x.Name).ToList().ForEach(delegate(AspNetUser obj) { result.AgentList.Add(new SelectItemList() { Value = obj.Id, Text = obj.Name, MediaTypeId = 0 }); }); } }); } catch (Exception ex) { result = null; } return(result); }
public GenericRepository(SocialCRMEntities context) { this.context = context; this.dbSet = context.Set <TEntity>(); }