// GET: CompanyPushNotifications/Create public IActionResult Create() { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); CompanyPushNotificationViewModel s = new CompanyPushNotificationViewModel(); s.SentAt = DateTime.Now; s.CompanyID = _user.CompanyID; s.UserID = _user.ID; s.SenderName = _user.Name; DataAccessLayer dla = new DataAccessLayer(_context); string deptID = _user.Categories; // Add group checkboxes var listOfAllGroups = dla.GetListGroups(_user.CompanyID); foreach (var seg in listOfAllGroups) { s.AvailableGroups.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Add topic checkboxes var listOfAllTopics = dla.GetListTopics(_user.CompanyID); foreach (var seg in listOfAllTopics) { s.AvailableTopics.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Add type checkboxes var listOfAllTypeOfUser = dla.GetListTypeOfUser(_user.CompanyID); foreach (var seg in listOfAllTypeOfUser) { s.AvailableTypeOfUser.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Add language checkboxes var listOfAllLanguages = dla.GetListLanguages(_user.CompanyID, _rlo); foreach (var seg in listOfAllLanguages) { s.AvailableLanguages.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Get location dropdown data s.Countries = dla.GetCountries(); s.States = dla.GetNullStatesOrCities(); s.Cities = dla.GetNullStatesOrCities(); return(View(s)); }
// GET: SegmentArticles/Articlelist/id of segment public async Task <IActionResult> UserArticleSearch(string searchString) { if (searchString == null) { return(NotFound()); } _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); var segmentid = HttpContext.Session.GetInt32("SegmentListID"); DataAccessLayer dla = new DataAccessLayer(_context); //Also add the Segment to the Viewbag so we can get the Image CompanySegment cs = await _context.CompanySegment.FirstOrDefaultAsync(m => m.ID == segmentid && m.CompanyID == _cpy.ID); var segmentArticle = dla.GetArticlesListBasedOnThisUsersFilters(_user, "", cs); ViewBag.Segment = cs; if (segmentArticle == null) { return(NotFound()); } ViewBag.UploadsLocation = "https://s3-us-west-2.amazonaws.com/wootrixv2uploadfiles/images/Uploads/"; return(View(segmentArticle)); }
// GET: CompanySegments/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); var companySegment = await _context.CompanySegment.FindAsync(id); if (companySegment == null) { return(NotFound()); } CompanySegmentViewModel s = new CompanySegmentViewModel(); s.Order = companySegment.Order; s.Title = companySegment.Title; s.PublishDate = companySegment.PublishDate; s.FinishDate = companySegment.FinishDate; s.StandardColor = companySegment.StandardColor; s.ThemeColor = companySegment.ThemeColor; s.ClientName = (companySegment.ClientName ?? _user.Name); // s.ClientLogoImage = FormFileHelper.PhysicalToIFormFile(new FileInfo(companySegment.ClientLogoImage)); s.Department = companySegment.Department; s.Tags = companySegment.Tags; DataAccessLayer dla = new DataAccessLayer(_context); s.Departments = dla.GetDepartments(_user.CompanyID); return(View(s)); }
public async Task <IActionResult> Home(string id) { if (id == null) { return(NotFound()); } ViewBag.UploadsLocation = "https://s3-us-west-2.amazonaws.com/wootrixv2uploadfiles/images/Uploads/"; var company = await _context.Company .FirstOrDefaultAsync(m => m.CompanyName == id); if (company == null) { return(NotFound()); } // Now for users we need to show them articles on the home page so get them in the ViewBag for display HttpContext.Session.SetInt32("CompanyID", company.ID); HttpContext.Session.SetString("CompanyName", company.CompanyName); HttpContext.Session.SetString("CompanyTextMain", company.CompanyTextMain); HttpContext.Session.SetString("CompanyTextSecondary", company.CompanyTextSecondary); HttpContext.Session.SetString("CompanyMainFontColor", company.CompanyMainFontColor); HttpContext.Session.SetString("CompanyLogoImage", company.CompanyLogoImage); HttpContext.Session.SetString("CompanyFocusImage", company.CompanyFocusImage ?? ""); HttpContext.Session.SetString("CompanyBackgroundImage", company.CompanyBackgroundImage ?? ""); HttpContext.Session.SetString("CompanyHighlightColor", company.CompanyHighlightColor); HttpContext.Session.SetString("CompanyHeaderFontColor", company.CompanyHeaderFontColor); HttpContext.Session.SetString("CompanyHeaderBackgroundColor", company.CompanyHeaderBackgroundColor); HttpContext.Session.SetString("CompanyBackgroundColor", company.CompanyBackgroundColor); HttpContext.Session.SetInt32("CompanyNumberOfUsers", company.CompanyNumberOfUsers); if (_signInManager.IsSignedIn(User)) { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); //_cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); ViewBag.User = _user; ViewBag.CommentUnderReviewCount = _dla.GetArticleReviewCommentCount(_user.CompanyID); if (_user.Role == Roles.User) { System.Console.WriteLine("***********Getting Segments************"); ViewBag.Segments = _dla.GetSegmentsList(_user.CompanyID, _user, "", "").OrderBy(m => m.Order); } //So everytime a user comes to the home page it will update their notification status into the session var usrNotifications = _dla.GetNotificationsMatchingUserFilters(_user); int numberOfNotifications = usrNotifications.Count; HttpContext.Session.SetInt32("NumberOfNotifications", numberOfNotifications); } // Saving all this company stuff to the session so the layout isn't dependent on the model // Note that it is all non-sensitive stuff return(View(company)); }
// GET: CompanyPushNotifications public async Task <IActionResult> Index() { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); var usrNotifications = _dla.GetNotificationsMatchingUserFilters(_user); int numberOfNotifications = usrNotifications.Count; HttpContext.Session.SetInt32("NumberOfNotifications", numberOfNotifications); return(View(await _context.CompanyPushNotification.Where(m => m.CompanyID == _user.CompanyID).OrderByDescending(m => m.SentAt).ToListAsync())); }
// GET: CompanySegments public async Task <IActionResult> UserSegmentSearch(string SearchString) { DataAccessLayer dla = new DataAccessLayer(_context); _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); var segments = dla.GetSegmentsList(_cpy.ID, _user, SearchString, ""); ViewBag.UploadsLocation = "https://s3-us-west-2.amazonaws.com/wootrixv2uploadfiles/images/Uploads/"; return(View(segments)); }
public async Task <IActionResult> Notifications() { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); var notifications = _dla.GetNotificationsMatchingUserFilters(_user); _user.LastViewedNotificationsOn = System.DateTime.Now; _context.Update(_user); await _context.SaveChangesAsync(); HttpContext.Session.SetInt32("NumberOfNotifications", 0); return(View(notifications)); }
// GET: CompanySegments/Details/5 public async Task <IActionResult> Details(int id) { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); HttpContext.Session.SetInt32("SegmentID", id); CompanySegment cs = await _context.CompanySegment.FirstOrDefaultAsync(m => m.ID == id && m.CompanyID == _cpy.ID); var segmentArticle = _context.SegmentArticle .Where(n => n.CompanyID == _cpy.ID) .Where(m => m.Segments.Contains(cs.Title)); // OK so now we are going to set the article Order field to be as show in the Segments so its easier to work with. // We will need to save the segments back again if there is a change foreach (SegmentArticle item in segmentArticle) { //Split the segments into a list, grab their order and increment it then save the change var segments = item.Segments; var segmentsList = item.Segments.Split("|"); foreach (string segmentTitleAndOrder in segmentsList) { if (segmentTitleAndOrder.Contains(cs.Title)) { //Get the order and increment var titleAndOrder = segmentTitleAndOrder.Split("/"); bool success = int.TryParse(titleAndOrder[1], out int ord); // Set the article Order item.Order = ord; } } _context.Update(item); } _context.SaveChanges(); segmentArticle = _context.SegmentArticle .Where(n => n.CompanyID == cs.CompanyID) .Where(m => m.Segments.Contains(cs.Title)) .OrderBy(p => p.Order); //Also add the Segment to the Viewbag so we can get the Image ViewBag.Segment = cs; if (segmentArticle == null) { return(NotFound()); } return(View(await segmentArticle.ToListAsync())); }
public IActionResult UpdateGraphs(GraphFilters filters) { if (!string.IsNullOrWhiteSpace(filters.ToString())) { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); var companyID = _user.CompanyID; //We need to build the datasets for the graphs into the viewbag var articlesRead = _context.ArticleReporting.Where(m => m.CompanyID == companyID && m.SegmentName == filters.magazine); string[] articles = articlesRead.Select(d => d.ArticleName).Distinct().ToArray(); SetupViewsPerArticleReport(articlesRead); return(Json(articles)); } return(null); }
// GET: ArticleReportings public async Task <IActionResult> Index() { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); var companyID = _user.CompanyID; //We need to build the datasets for the graphs into the viewbag var articlesRead = _context.ArticleReporting.Where(m => m.CompanyID == companyID); var totalArticles = _context.SegmentArticle.Where(m => m.CompanyID == companyID); AddFilters(companyID); SetupOSReport(articlesRead); SetupPlatformReport(articlesRead); SetupViewsByLocation(articlesRead); SetupViewsPerArticleReport(articlesRead); return(View(await articlesRead.ToListAsync())); }
// GET: CompanySegments/Delete/5 public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); var companySegment = await _context.CompanySegment .FirstOrDefaultAsync(m => m.ID == id); if (companySegment == null) { return(NotFound()); } return(View(companySegment)); }
// GET: CompanySegments/Create public IActionResult Create() { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); CompanySegmentViewModel s = new CompanySegmentViewModel(); s.Order = 1; s.PublishDate = DateTime.Now.Date; s.FinishDate = DateTime.Now.AddYears(10).Date; s.StandardColor = HttpContext.Session.GetString("CompanyHeaderBackgroundColor"); s.ThemeColor = HttpContext.Session.GetString("CompanyHighlightColor"); s.ClientName = _user.Name; //s.ClientLogoImage = _user.photoUrl; var cp = _user.CompanyID; DataAccessLayer dla = new DataAccessLayer(_context); s.Departments = dla.GetDepartments(cp); return(View(s)); }
// GET: SegmentArticles/Articlelist/id of segment public async Task <IActionResult> ArticleList(int id) { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); HttpContext.Session.SetInt32("SegmentListID", id); HttpContext.Session.SetInt32("CompanyID", _cpy.ID); HttpContext.Session.SetString("CompanyName", _cpy.CompanyName); HttpContext.Session.SetString("CompanyTextMain", _cpy.CompanyTextMain); HttpContext.Session.SetString("CompanyTextSecondary", _cpy.CompanyTextSecondary); HttpContext.Session.SetString("CompanyMainFontColor", _cpy.CompanyMainFontColor); HttpContext.Session.SetString("CompanyLogoImage", _cpy.CompanyLogoImage); HttpContext.Session.SetString("CompanyFocusImage", _cpy.CompanyFocusImage ?? ""); HttpContext.Session.SetString("CompanyBackgroundImage", _cpy.CompanyBackgroundImage ?? ""); HttpContext.Session.SetString("CompanyHighlightColor", _cpy.CompanyHighlightColor); HttpContext.Session.SetString("CompanyHeaderFontColor", _cpy.CompanyHeaderFontColor); HttpContext.Session.SetString("CompanyHeaderBackgroundColor", _cpy.CompanyHeaderBackgroundColor); HttpContext.Session.SetString("CompanyBackgroundColor", _cpy.CompanyBackgroundColor); HttpContext.Session.SetInt32("CompanyNumberOfUsers", _cpy.CompanyNumberOfUsers); ViewBag.UploadsLocation = "https://s3-us-west-2.amazonaws.com/wootrixv2uploadfiles/images/Uploads/"; DataAccessLayer dla = new DataAccessLayer(_context); // Now for users we need to show them articles on the home page so get them in the ViewBag for display //Also add the Segment to the Viewbag so we can get the Image CompanySegment cs = await _context.CompanySegment.FirstOrDefaultAsync(m => m.ID == id && m.CompanyID == _cpy.ID); var segmentArticle = dla.GetArticlesListBasedOnThisUsersFilters(_user, "", cs).OrderBy(m => m.Order); if (segmentArticle == null) { return(NotFound()); } ViewBag.SegmentCoverImage = cs.CoverImage ?? ""; ViewBag.SegmentTitle = cs.Title ?? ""; ViewBag.CompanyName = _user.CompanyName ?? ""; return(View(segmentArticle)); }
public async Task <IActionResult> Create(CompanyPushNotificationViewModel cpnVM) { if (ModelState.IsValid) { var cpn = new CompanyPushNotification(); _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); //MessageTitle,MessageBody,MessageType,SentAt,SenderName,Languages,Groups,Topics,TypeOfUser,Country,State,City cpn.MessageTitle = cpnVM.MessageTitle; cpn.MessageType = cpnVM.MessageType; cpn.MessageBody = cpnVM.MessageBody; cpn.SenderName = _user.Name; cpn.SentAt = DateTime.Now; cpn.CompanyID = _user.CompanyID; cpn.UserID = _user.ID; cpn.Languages = string.Join("|", cpnVM.SelectedLanguages); cpn.Groups = string.Join("|", cpnVM.SelectedGroups); cpn.Topics = string.Join("|", cpnVM.SelectedTopics); cpn.TypeOfUser = string.Join("|", cpnVM.SelectedTypeOfUser); if (cpnVM.Country != null && cpnVM.Country != "") { cpn.Country = _context.LocationCountries.FirstOrDefault(m => m.country_code == cpnVM.Country).country_name; } if (cpnVM.State != null && cpnVM.State != "") { cpn.State = _context.LocationStates.FirstOrDefault(n => n.country_code == cpnVM.Country && n.state_code == cpnVM.State).state_name; } cpn.City = cpnVM.City; _context.Add(cpn); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cpnVM)); }
// GET: CompanySegments public async Task <IActionResult> Index() { //Get the company name out the session and use it as a filter for the groups returned // We also need to filter on department. // So if a segment is set to only be Editable by Company Admins of Department IT, // then if the current Company Admin is in Department Marketing they wont see it. // Note that if the segment doesn't have a department set, everyone sees it // Get current user department _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); var department = _user.Categories; //bad naming for the old DB i know List <CompanySegment> ctx; // If the user doesn't have a department don't filter on it if (!string.IsNullOrWhiteSpace(department)) { ctx = await _context.CompanySegment .Where(m => m.CompanyID == _cpy.ID) .Where(m => m.Department == department) .OrderBy(m => m.Order) .ToListAsync(); } else { ctx = await _context.CompanySegment .Where(m => m.CompanyID == _cpy.ID) .OrderBy(m => m.Order) .ToListAsync(); } ViewBag.UploadsLocation = "https://s3-us-west-2.amazonaws.com/wootrixv2uploadfiles/images/Uploads/"; return(View(ctx)); }
public async Task <IActionResult> Create(SegmentArticleViewModel sa) { var myArticle = new SegmentArticle(); _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); //Have to check the article title isn't already used var existingArticle = _context.SegmentArticle.FirstOrDefault(n => n.Title == sa.Title && n.CompanyID == sa.CompanyID); if (existingArticle == null) { if (ModelState.IsValid) { //ID,Order,Title,CoverImage,CoverImageMobileFriendly,PublishDate,FinishDate,ClientName,ClientLogoImage,ThemeColor,StandardColor,Draft,Department,Tags myArticle.CompanyID = _user.CompanyID; myArticle.Title = WebUtility.HtmlEncode(sa.Title); myArticle.PublishFrom = sa.PublishFrom ?? DateTime.Now.AddDays(-1); myArticle.PublishTill = sa.PublishTill ?? DateTime.Now.AddYears(10); myArticle.AllowComments = sa.AllowComments; myArticle.ArticleContent = WebUtility.HtmlEncode(sa.ArticleContent); myArticle.Author = (sa.Author ?? _user.Name); //if null set to be user name myArticle.CreatedBy = _user.Name; myArticle.ArticleUrl = WebUtility.HtmlEncode(sa.ArticleUrl); myArticle.Order = 1; myArticle.Tags = WebUtility.HtmlEncode(sa.Tags); myArticle.Languages = string.Join("|", sa.SelectedLanguages); myArticle.Groups = string.Join("|", sa.SelectedGroups); myArticle.Topics = string.Join("|", sa.SelectedTopics); myArticle.TypeOfUser = string.Join("|", sa.SelectedTypeOfUser); if (sa.Country != null && sa.Country != "") { myArticle.Country = _context.LocationCountries.FirstOrDefault(m => m.country_code == sa.Country).country_name; } if (sa.State != null && sa.State != "") { myArticle.State = _context.LocationStates.FirstOrDefault(n => n.country_code == sa.Country && n.state_code == sa.State).state_name; } myArticle.City = sa.City; //Now we need to get what the article ID will be as it isn't normally generated till created. int artID = _context.SegmentArticle.OrderByDescending(u => u.ID).FirstOrDefault().ID + 1; IFormFile img = sa.Image; if (img != null) { await _dla.UploadFileToS3(img, _user.CompanyName + "_" + artID + "_" + img.FileName, "images/Uploads/Articles"); //The file has been saved to disk - now save the file name to the DB myArticle.Image = img.FileName; } IFormFile vid = sa.EmbeddedVideo; if (vid != null) { await _dla.UploadFileToS3(vid, _user.CompanyName + "_" + artID + "_" + vid.FileName, "images/Uploads/Articles"); //The file has been saved to disk - now save the file name to the DB myArticle.EmbeddedVideo = vid.FileName; } // As they want order to be associated with segment now im having to smush it in with the current field....a bit ugly if (sa.SelectedSegments.Count > 0) { myArticle.Segments = CreateSegmentsStringWithOrder1(sa.SelectedSegments); } _context.Add(myArticle); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } else { // Article title already exists ModelState.AddModelError(string.Empty, "Article Title already exists - please choose something unique"); } DataAccessLayer dla = new DataAccessLayer(_context); var listOfAllSegements = dla.GetArticleSegments(_user.CompanyID); foreach (var seg in listOfAllSegements) { sa.AvailableSegments.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Add group checkboxes var listOfAllGroups = dla.GetListGroups(_user.CompanyID); foreach (var seg in listOfAllGroups) { sa.AvailableGroups.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Add topic checkboxes var listOfAllTopics = dla.GetListTopics(_user.CompanyID); foreach (var seg in listOfAllTopics) { sa.AvailableTopics.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Add type checkboxes var listOfAllTypeOfUser = dla.GetListTypeOfUser(_user.CompanyID); foreach (var seg in listOfAllTypeOfUser) { sa.AvailableTypeOfUser.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Add language checkboxes var listOfAllLanguages = dla.GetListLanguages(_user.CompanyID, _rlo); foreach (var seg in listOfAllLanguages) { sa.AvailableLanguages.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Get location dropdown data sa.Countries = dla.GetCountries(); sa.States = dla.GetNullStatesOrCities(); sa.Cities = dla.GetNullStatesOrCities(); return(View(sa)); }
// GET: SegmentArticles/Create public IActionResult Create() { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); SegmentArticleViewModel s = new SegmentArticleViewModel(); s.Order = 1; s.PublishFrom = DateTime.Now.Date; s.PublishTill = DateTime.Now.AddYears(10).Date; s.CompanyID = _user.CompanyID; s.Author = _user.Name; s.AllowComments = true; DataAccessLayer dla = new DataAccessLayer(_context); string deptID = _user.Categories; List <SelectListItem> listOfAllSegements; if (!string.IsNullOrEmpty(deptID)) { listOfAllSegements = dla.GetArticleSegments(_user.CompanyID, deptID); } else { listOfAllSegements = dla.GetArticleSegments(_user.CompanyID); } foreach (var seg in listOfAllSegements) { s.AvailableSegments.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Add group checkboxes var listOfAllGroups = dla.GetListGroups(_user.CompanyID); foreach (var seg in listOfAllGroups) { s.AvailableGroups.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Add topic checkboxes var listOfAllTopics = dla.GetListTopics(_user.CompanyID); foreach (var seg in listOfAllTopics) { s.AvailableTopics.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Add type checkboxes var listOfAllTypeOfUser = dla.GetListTypeOfUser(_user.CompanyID); foreach (var seg in listOfAllTypeOfUser) { s.AvailableTypeOfUser.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Add language checkboxes var listOfAllLanguages = dla.GetListLanguages(_user.CompanyID, _rlo); foreach (var seg in listOfAllLanguages) { s.AvailableLanguages.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } // Get location dropdown data s.Countries = dla.GetCountries(); s.States = dla.GetNullStatesOrCities(); s.Cities = dla.GetNullStatesOrCities(); return(View(s)); }
// GET: SegmentArticles/Article/5 public async Task <IActionResult> Article(int?id) { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); HttpContext.Session.SetInt32("CompanyID", _cpy.ID); HttpContext.Session.SetString("CompanyName", _cpy.CompanyName); HttpContext.Session.SetString("CompanyTextMain", _cpy.CompanyTextMain); HttpContext.Session.SetString("CompanyTextSecondary", _cpy.CompanyTextSecondary); HttpContext.Session.SetString("CompanyMainFontColor", _cpy.CompanyMainFontColor); HttpContext.Session.SetString("CompanyLogoImage", _cpy.CompanyLogoImage); HttpContext.Session.SetString("CompanyFocusImage", _cpy.CompanyFocusImage ?? ""); HttpContext.Session.SetString("CompanyBackgroundImage", _cpy.CompanyBackgroundImage ?? ""); HttpContext.Session.SetString("CompanyHighlightColor", _cpy.CompanyHighlightColor); HttpContext.Session.SetString("CompanyHeaderFontColor", _cpy.CompanyHeaderFontColor); HttpContext.Session.SetString("CompanyHeaderBackgroundColor", _cpy.CompanyHeaderBackgroundColor); HttpContext.Session.SetString("CompanyBackgroundColor", _cpy.CompanyBackgroundColor); HttpContext.Session.SetInt32("CompanyNumberOfUsers", _cpy.CompanyNumberOfUsers); ViewBag.UploadsLocation = "https://s3-us-west-2.amazonaws.com/wootrixv2uploadfiles/images/Uploads/"; var segID = HttpContext.Session.GetInt32("SegmentListID"); if (id == null) { return(NotFound()); } DataAccessLayer dla = new DataAccessLayer(_context); ViewBag.CommentCount = dla.GetArticleApprovedCommentCount(id ?? 0); ViewBag.Comments = dla.GetArticleCommentsList(id ?? 0); var segmentArticle = await _context.SegmentArticle .FirstOrDefaultAsync(m => m.ID == id); if (segmentArticle == null) { return(NotFound()); } if (!string.IsNullOrEmpty(segmentArticle.ArticleUrl)) { Response.Redirect(segmentArticle.ArticleUrl); } //OK for reporting we need to get some data about the user and save it to the ArticleReporting Table ArticleReporting ar = new ArticleReporting(); ar.CompanyID = _user.CompanyID; ar.UserID = _user.ID; ar.UserName = _user.Name; ar.SegmentID = segID ?? 0; ar.SegmentName = _context.CompanySegment.FirstOrDefault(m => m.ID == segID).Title; ar.ArticleID = segmentArticle.ID; ar.ArticleName = segmentArticle.Title; ar.ArticleReadTime = System.DateTime.Now; ar.Country = _user.Country; ar.State = _user.State; ar.City = _user.City; var userAgent = Request.Headers["User-Agent"]; UserAgent ua = new UserAgent(userAgent); ar.DeviceType = ua.Browser.Name + " " + ua.Browser.Version; ar.OSType = ua.OS.Name + " " + ua.OS.Version; _context.Add(ar); await _context.SaveChangesAsync(); return(View(segmentArticle)); }
public async Task <IActionResult> Edit(int id, CompanySegmentViewModel cps) { if (id != cps.ID) { return(NotFound()); } _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); //Initialise a new companysegment CompanySegment mySegment = await _context.CompanySegment.FindAsync(id); //Have to check the Segment title isn't already used - it gets weird otherwise var existingSeg = _context.SegmentArticle.FirstOrDefault(n => n.Title == cps.Title && n.CompanyID == cps.CompanyID); if (existingSeg == null) { if (ModelState.IsValid) { //ID,Order,Title,CoverImage,CoverImageMobileFriendly,PublishDate,FinishDate,ClientName,ClientLogoImage,ThemeColor,StandardColor,Draft,Department,Tags mySegment.CompanyID = _user.CompanyID; mySegment.PublishDate = cps.PublishDate; mySegment.FinishDate = cps.FinishDate; mySegment.ClientName = cps.ClientName; mySegment.ThemeColor = cps.ThemeColor; mySegment.StandardColor = cps.StandardColor; mySegment.Draft = DateTime.Now > cps.PublishDate ? false : true; mySegment.Department = cps.Department; mySegment.Tags = cps.Tags; IFormFile coverImage = cps.CoverImage; if (coverImage != null) { await _dla.UploadFileToS3(coverImage, _user.CompanyName + "_" + coverImage.FileName, "images/Uploads"); mySegment.CoverImage = coverImage.FileName; } IFormFile coverImageMB = cps.CoverImageMobileFriendly; if (coverImageMB != null) { await _dla.UploadFileToS3(coverImageMB, _user.CompanyName + "_" + coverImageMB.FileName, "images/Uploads"); //The file has been saved to disk - now save the file name to the DB mySegment.CoverImageMobileFriendly = coverImageMB.FileName; } IFormFile cli = cps.ClientLogoImage; if (cli != null) { await _dla.UploadFileToS3(cli, _user.CompanyName + "_" + cli.FileName, "images/Uploads"); //The file has been saved to disk - now save the file name to the DB mySegment.CoverImageMobileFriendly = cli.FileName; } try { // Done later to avoid ordering failures if the image upload fails. if (mySegment.Order != 1) { // We only need to decrement articles above it (lower order) InsertAtOrder1(mySegment.Order ?? 1); } mySegment.Order = 1; // Ok but what about the connected articles? We need to update every article segments field and change the old val to the new // If the title changed if (mySegment.Title != cps.Title) { foreach (var art in _context.SegmentArticle.Where(m => m.CompanyID == _user.CompanyID)) { if (art.Segments.Contains(mySegment.Title)) { var oldSegments = art.Segments; var newSegments = oldSegments.Replace(mySegment.Title, cps.Title); art.Segments = newSegments; _context.Update(art); } } } mySegment.Title = cps.Title; _context.Update(mySegment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompanySegmentExists(cps.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } } else { // Article title already exists ModelState.AddModelError(string.Empty, "Magazine Title already exists - please choose something unique"); } return(RedirectToAction("Edit", new { id = cps.ID })); }
public async Task <IActionResult> Index(FilterData data, int?id) { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); var companyID = _user.CompanyID; //We need to build the datasets for the graphs into the viewbag var totalArticles = _context.SegmentArticle.Where(m => m.CompanyID == companyID && (data.SelectedGroups.Count() <= 0 || data.SelectedGroups.Any(x => x == m.Groups)) && (data.SelectedTypeOfUser.Count() <= 0 || data.SelectedTypeOfUser.Any(x => x == m.TypeOfUser)) && (data.SelectedTopics.Count() <= 0 || data.SelectedTopics.Any(x => x == m.Topics)) && (data.SelectedLanguages.Count <= 0 || data.SelectedLanguages.Any(x => x == m.Languages))); var articlesRead = _context.ArticleReporting.Where(m => m.CompanyID == companyID && (data.FromDate == null || m.ArticleReadTime >= data.FromDate) && (data.ToDate == null || m.ArticleReadTime <= data.ToDate) && (data.SelectedSegments.Count() <= 0 || data.SelectedSegments.Any(y => y == m.SegmentName)) && (data.SelectedArticles.Count() <= 0 || data.SelectedArticles.Any(y => y == m.ArticleName)) && (data.Country == null || m.Country == data.Country) && (data.State == null || m.State == data.State) && (data.City == null || m.City == data.City)); var segmentArticle = _context.SegmentArticle.Where(x => x.CompanyID == companyID).ToList(); var segments = from sa in _context.SegmentArticle join ar in _context.ArticleReporting on sa.CompanyID equals ar.CompanyID into joinedSegment from ar in joinedSegment.DefaultIfEmpty() where sa.CompanyID == companyID && (data.FromDate == null || ar.ArticleReadTime >= data.FromDate) && (data.ToDate == null || ar.ArticleReadTime <= data.ToDate) && (data.Country == null || sa.Country == data.Country) && (data.State == null || sa.State == data.State) && (data.City == null || sa.City == data.City) && (data.SelectedGroups.Count <= 0 || data.SelectedGroups.Any(x => x == sa.Groups)) && (data.SelectedTypeOfUser.Count <= 0 || data.SelectedTypeOfUser.Any(x => x == sa.TypeOfUser)) && (data.SelectedTopics.Count <= 0 || data.SelectedTopics.Any(x => x == sa.Topics)) && (data.SelectedLanguages.Count <= 0 || data.SelectedLanguages.Any(x => x == sa.Languages)) && (data.SelectedSegments.Count <= 0 || data.SelectedSegments.Any(x => x == ar.SegmentName)) && (data.SelectedArticles.Count() <= 0 || data.SelectedArticles.Any(y => y == ar.ArticleName)) group new { sa, ar } by new { ar.SegmentID, ar.SegmentName } into sr select new { CompanyID = companyID, SegmentID = sr.Key.SegmentID, SegmentName = sr.Key.SegmentName, PreviewCount = sr.Select(x => x.ar).Count(), PreviewInPercentage = (sr.Select(x => x.ar).Count()) * 100 / (_context.ArticleReporting.Select(s => s.SegmentName).Count()) }; ViewBag.Magazine = segments.Select(y => new Magazine { SegmentId = y.SegmentID, SegmentName = y.SegmentName, Previews = y.PreviewCount, percentageMagazine = y.PreviewInPercentage }).Take(10).Distinct(); ViewBag.Article = _context.ArticleReporting.Where(x => segments.Any(sg => sg.SegmentID == x.SegmentID)) .Select(ar => new Article() { ArticleID = ar.ArticleID, ArticleName = ar.ArticleName, Previews = segments.FirstOrDefault(x => x.SegmentID == ar.SegmentID).PreviewCount, percentageArticle = segments.FirstOrDefault(x => x.SegmentID == ar.SegmentID).PreviewInPercentage, }).Take(10).Distinct(); ViewBag.Topics = segmentArticle.Where(x => segments.Any(sg => x.Segments.Contains(sg.SegmentName))) .Select(sa => new Topics() { TopicID = sa.CompanyID, TopiceName = sa.Topics, Previews = segments.FirstOrDefault(x => x.CompanyID == sa.CompanyID).PreviewCount, percentageTopic = segments.FirstOrDefault(x => x.CompanyID == sa.CompanyID).PreviewInPercentage, }).ToList(); ViewBag.Groups = segmentArticle.Where(x => segments.Any(sg => x.Segments.Contains(sg.SegmentName))) .Select(sa => new Groups { GroupID = sa.CompanyID, GroupName = sa.Groups, Previews = segments.FirstOrDefault(x => x.CompanyID == sa.CompanyID).PreviewCount, percentageGroup = segments.FirstOrDefault(x => x.CompanyID == sa.CompanyID).PreviewInPercentage }).Take(10).Distinct(); ViewBag.User = segmentArticle.Where(x => segments.Any(sg => x.Segments.Contains(sg.SegmentName))) .Select(sa => new Users { UserID = sa.CompanyID, UserName = sa.TypeOfUser, Previews = segments.FirstOrDefault(x => x.CompanyID == sa.CompanyID).PreviewCount, percentageUser = segments.FirstOrDefault(x => x.CompanyID == sa.CompanyID).PreviewInPercentage }).Take(10).Distinct(); ViewBag.Languages = segmentArticle.Where(x => segments.Any(sg => x.Segments.Contains(sg.SegmentName))) .Select(sa => new Languages { LanguageID = sa.CompanyID, LanguageName = sa.Languages, Previews = segments.FirstOrDefault(x => x.CompanyID == sa.CompanyID).PreviewCount, percentageLanguage = segments.FirstOrDefault(x => x.CompanyID == sa.CompanyID).PreviewInPercentage }).Take(10).Distinct(); ViewBag.City = _context.ArticleReporting.Where(x => segments.Any(sg => sg.SegmentID == x.SegmentID)) .Select(ar => new City { CityID = ar.CompanyID, Citys = ar.City, Previews = segments.FirstOrDefault(x => x.SegmentID == ar.SegmentID).PreviewCount, percentageCity = segments.FirstOrDefault(x => x.SegmentID == ar.SegmentID).PreviewInPercentage, }).Take(10).Distinct(); ViewBag.States = _context.ArticleReporting.Where(x => segments.Any(sg => sg.SegmentID == x.SegmentID)) .Select(ar => new States { StateID = ar.CompanyID, State = ar.State, Previews = segments.FirstOrDefault(x => x.SegmentID == ar.SegmentID).PreviewCount, percentageState = segments.FirstOrDefault(x => x.SegmentID == ar.SegmentID).PreviewInPercentage, }).Take(10).Distinct(); ViewBag.Country = _context.ArticleReporting.Where(x => segments.Any(sg => sg.SegmentID == x.SegmentID)) .Select(ar => new Countrys { CountryID = ar.CompanyID, Country = ar.State, Previews = segments.FirstOrDefault(x => x.SegmentID == ar.SegmentID).PreviewCount, percentageCountry = segments.FirstOrDefault(x => x.SegmentID == ar.SegmentID).PreviewInPercentage, }).Take(10).Distinct(); AddFilters(companyID); SetupOSReport(articlesRead); SetupPlatformReport(articlesRead); SetupViewsByLocation(articlesRead); SetupViewsPerArticleReport(articlesRead); if (!string.IsNullOrWhiteSpace(id.ToString())) { //Admin user has selected a companyID so set the current session stuff appropriately var companyName = _context.Company.FirstOrDefaultAsync(n => n.ID == id).GetAwaiter().GetResult().CompanyName; HttpContext.Session.SetInt32("id", id ?? 0); HttpContext.Session.SetString("CompanyName", companyName); } DataAccessLayer dla = new DataAccessLayer(_context); _user1 = _userManager.GetUserAsync(User).GetAwaiter().GetResult(); var reportingModel = new Reporting() { Reports = await articlesRead.ToListAsync(), FilterDetaails = GetFilterData(dla) }; return(View(reportingModel)); }
// GET: SegmentArticles/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); var segmentArticle = await _context.SegmentArticle.FindAsync(id); if (segmentArticle == null) { return(NotFound()); } DataAccessLayer dla = new DataAccessLayer(_context); SegmentArticleViewModel s = new SegmentArticleViewModel(); s.Order = segmentArticle.Order; s.ArticleUrl = WebUtility.HtmlDecode(segmentArticle.ArticleUrl); s.Title = WebUtility.HtmlDecode(segmentArticle.Title); //s.Image = segmentArticle.Image; TODO still need to fix this crap //s.EmbeddedVideo = segmentArticle.EmbeddedVideo; s.ArticleContent = WebUtility.HtmlDecode(segmentArticle.ArticleContent); s.PublishFrom = segmentArticle.PublishFrom; s.PublishTill = segmentArticle.PublishTill; s.CompanyID = segmentArticle.CompanyID; s.Author = (segmentArticle.Author == null || segmentArticle.Author == "" ? _user.Name : segmentArticle.Author); s.AllowComments = segmentArticle.AllowComments; s.Tags = WebUtility.HtmlDecode(segmentArticle.Tags); s.CreatedBy = _user.Name; // Get location dropdown data s.Countries = dla.GetCountries(); s.States = dla.GetNullStatesOrCities(); s.Cities = dla.GetNullStatesOrCities(); if (segmentArticle.Segments != null && segmentArticle.Segments != "") { s.AvailableSegments = RemoveDigitsAndSlashes(segmentArticle.Segments).Split('|').Select(x => new SelectListItem { Text = x, Value = x, Selected = true }).ToList(); } //Add any options not already in the segmentlist string deptID = _user.Categories; List <SelectListItem> listOfAllSegements; if (!string.IsNullOrEmpty(deptID)) { listOfAllSegements = dla.GetArticleSegments(_user.CompanyID, deptID); } else { listOfAllSegements = dla.GetArticleSegments(_user.CompanyID); } foreach (var seg in listOfAllSegements) { var match = s.AvailableSegments.FirstOrDefault(stringToCheck => stringToCheck.Value.Contains(seg.Value)); if (match == null) { //if no match (not in the list) then add it s.AvailableSegments.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } } if (segmentArticle.Groups != null && segmentArticle.Groups != "") { s.AvailableGroups = segmentArticle.Groups.Split('|').Select(x => new SelectListItem { Text = x, Value = x, Selected = true }).ToList(); } //Add any options not already in the segmentlist var listOfAllGroups = dla.GetListGroups(_user.CompanyID); foreach (var seg in listOfAllGroups) { if (s.AvailableGroups.FirstOrDefault(stringToCheck => stringToCheck.Value.Contains(seg.Value)) == null) { //if no match (not in the list) then add it s.AvailableGroups.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } } if (segmentArticle.Topics != null && segmentArticle.Topics != "") { s.AvailableTopics = segmentArticle.Topics.Split('|').Select(x => new SelectListItem { Text = x, Value = x, Selected = true }).ToList(); } //Add any options not already in the segmentlist var listOfAllTopics = dla.GetListTopics(_user.CompanyID); foreach (var seg in listOfAllTopics) { if (s.AvailableTopics.FirstOrDefault(stringToCheck => stringToCheck.Value.Contains(seg.Value)) == null) { //if no match (not in the list) then add it s.AvailableTopics.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } } if (segmentArticle.TypeOfUser != null && segmentArticle.TypeOfUser != "") { s.AvailableTypeOfUser = segmentArticle.TypeOfUser.Split('|').Select(x => new SelectListItem { Text = x, Value = x, Selected = true }).ToList(); } //Add any options not already in the segmentlist var listOfAllTypeOfUser = dla.GetListTypeOfUser(_user.CompanyID); foreach (var seg in listOfAllTypeOfUser) { if (s.AvailableTypeOfUser.FirstOrDefault(stringToCheck => stringToCheck.Value.Contains(seg.Value)) == null) { //if no match (not in the list) then add it s.AvailableTypeOfUser.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } } if (segmentArticle.Languages != null && segmentArticle.Languages != "") { s.AvailableLanguages = segmentArticle.Languages.Split('|').Select(x => new SelectListItem { Text = x, Value = x, Selected = true }).ToList(); } //Add any options not already in the segmentlist var listOfAllLanguages = dla.GetListLanguages(_user.CompanyID, _rlo); foreach (var seg in listOfAllLanguages) { if (s.AvailableLanguages.FirstOrDefault(stringToCheck => stringToCheck.Value.Contains(seg.Value)) == null) { //if no match (not in the list) then add it s.AvailableLanguages.Add(new SelectListItem { Text = seg.Value, Value = seg.Value }); } } return(View(s)); }
// GET: ArticleReportings public async Task <IActionResult> Index(int?id) { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); var companyID = _user.CompanyID; //We need to build the datasets for the graphs into the viewbag var articlesRead = _context.ArticleReporting.Where(m => m.CompanyID == companyID); var totalArticles = _context.SegmentArticle.Where(m => m.CompanyID == companyID); ViewBag.Magazine = false; ViewBag.Magazine = _context.ArticleReporting.GroupBy(x => new { x.SegmentID, x.SegmentName }).Select(y => new Magazine { SegmentId = y.Key.SegmentID, SegmentName = y.Key.SegmentName, Previews = y.Count(), percentageMagazine = (y.Count()) * 100 / (_context.ArticleReporting.Select(s => s.SegmentName).Count()) }).Take(10).Distinct(); ViewBag.Article = _context.ArticleReporting.GroupBy(x => new { x.ArticleID, x.ArticleName }).Select(y => new Article { ArticleID = y.Key.ArticleID, ArticleName = y.Key.ArticleName, Previews = y.Count(), percentageArticle = (y.Count()) * 100 / (_context.ArticleReporting.Select(s => s.ArticleName).Count()) }).Take(10).Distinct(); ViewBag.Topics = _context.SegmentArticle.Where(y => !string.IsNullOrEmpty(y.Topics)).GroupBy(x => new { x.CompanyID, x.Topics }).Select(y => new Topics { TopicID = y.Key.CompanyID, TopiceName = y.Key.Topics, Previews = y.Count(), percentageTopic = (y.Count()) * 100 / (_context.SegmentArticle.Select(s => s.Topics).Count()) }).Take(10).Distinct(); ViewBag.Groups = _context.SegmentArticle.Where(y => !string.IsNullOrEmpty(y.Groups)).GroupBy(x => new { x.CompanyID, x.Groups }).Select(y => new Groups { GroupID = y.Key.CompanyID, GroupName = y.Key.Groups, Previews = y.Count(), percentageGroup = (y.Count()) * 100 / (_context.SegmentArticle.Select(s => s.Groups).Count()) }).Take(10).Distinct(); ViewBag.User = _context.SegmentArticle.Where(y => !string.IsNullOrEmpty(y.TypeOfUser)).GroupBy(x => new { x.CompanyID, x.TypeOfUser }).Select(y => new Users { UserID = y.Key.CompanyID, UserName = y.Key.TypeOfUser, Previews = y.Count(), percentageUser = (y.Count()) * 100 / (_context.SegmentArticle.Select(s => s.TypeOfUser).Count()) }).Take(10).Distinct(); ViewBag.Languages = _context.SegmentArticle.Where(y => !string.IsNullOrEmpty(y.Languages)).GroupBy(x => new { x.CompanyID, x.Languages }).Select(y => new Languages { LanguageID = y.Key.CompanyID, LanguageName = y.Key.Languages, Previews = y.Count(), percentageLanguage = (y.Count()) * 100 / (_context.SegmentArticle.Select(s => s.Languages).Count()) }).Take(10).Distinct(); ViewBag.City = _context.ArticleReporting.Where(y => !string.IsNullOrEmpty(y.City)).GroupBy(x => new { x.CompanyID, x.City }).Select(y => new City { CityID = y.Key.CompanyID, Citys = y.Key.City, Previews = y.Count(), percentageCity = (y.Count()) * 100 / (_context.ArticleReporting.Select(s => s.City).Count()) }).Take(10).Distinct(); ViewBag.States = _context.ArticleReporting.Where(y => !string.IsNullOrEmpty(y.State)).GroupBy(x => new { x.CompanyID, x.State }).Select(y => new States { StateID = y.Key.CompanyID, State = y.Key.State, Previews = y.Count(), percentageState = (y.Count()) * 100 / (_context.ArticleReporting.Select(s => s.State).Count()) }).Take(10).Distinct(); ViewBag.Country = _context.ArticleReporting.Where(y => !string.IsNullOrEmpty(y.Country)).GroupBy(x => new { x.CompanyID, x.Country }).Select(y => new Countrys { CountryID = y.Key.CompanyID, Country = y.Key.Country, Previews = y.Count(), percentageCountry = (y.Count()) * 100 / (_context.ArticleReporting.Select(s => s.Country).Count()) }).Take(10).Distinct(); AddFilters(companyID); SetupOSReport(articlesRead); SetupPlatformReport(articlesRead); SetupViewsByLocation(articlesRead); SetupViewsPerArticleReport(articlesRead); object FilterData = new FilterData(); if (!string.IsNullOrWhiteSpace(id.ToString())) { //Admin user has selected a companyID so set the current session stuff appropriately var companyName = _context.Company.FirstOrDefaultAsync(n => n.ID == id).GetAwaiter().GetResult().CompanyName; HttpContext.Session.SetInt32("id", id ?? 0); HttpContext.Session.SetString("CompanyName", companyName); } DataAccessLayer dla = new DataAccessLayer(_context); _user1 = _userManager.GetUserAsync(User).GetAwaiter().GetResult(); var reportingModel = new Reporting() { Reports = await articlesRead.ToListAsync(), FilterDetaails = GetFilterData(dla) }; return(View(reportingModel)); }
public async Task <IActionResult> Edit(int id, SegmentArticleViewModel sa) { if (id != sa.ID) { return(NotFound()); } _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); var myArticle = _context.SegmentArticle.Find(id); //Have to check the article title isn't already used var existingArticle = _context.SegmentArticle.FirstOrDefault(n => n.Title == sa.Title && n.CompanyID == sa.CompanyID); if (existingArticle == null) { if (ModelState.IsValid) { myArticle.ID = sa.ID; myArticle.CompanyID = _user.CompanyID; myArticle.Order = sa.Order ?? 1; myArticle.Title = WebUtility.HtmlEncode(sa.Title); myArticle.PublishFrom = sa.PublishFrom ?? DateTime.Now.AddDays(-1); myArticle.PublishTill = sa.PublishTill ?? DateTime.Now.AddYears(10); myArticle.AllowComments = sa.AllowComments; myArticle.ArticleContent = WebUtility.HtmlEncode(sa.ArticleContent); myArticle.Author = sa.Author; myArticle.Tags = WebUtility.HtmlEncode(sa.Tags); myArticle.ArticleUrl = WebUtility.HtmlEncode(sa.ArticleUrl); myArticle.Languages = string.Join("|", sa.SelectedLanguages); myArticle.Groups = string.Join("|", sa.SelectedGroups); myArticle.Topics = string.Join("|", sa.SelectedTopics); myArticle.TypeOfUser = string.Join("|", sa.SelectedTypeOfUser); myArticle.City = sa.City; if (sa.Country != null && sa.Country != "") { myArticle.Country = _context.LocationCountries.FirstOrDefault(m => m.country_code == sa.Country).country_name; } if (sa.State != null && sa.State != "") { myArticle.State = _context.LocationStates.FirstOrDefault(n => n.country_code == sa.Country && n.state_code == sa.State).state_name; } IFormFile img = sa.Image; if (img != null) { await _dla.UploadFileToS3(img, _user.CompanyName + "_" + id + "_" + img.FileName, "images/Uploads/Articles"); //The file has been saved to disk - now save the file name to the DB myArticle.Image = img.FileName; } IFormFile vid = sa.EmbeddedVideo; if (vid != null) { await _dla.UploadFileToS3(vid, _user.CompanyName + "_" + id + "_" + vid.FileName, "images/Uploads/Articles"); //The file has been saved to disk - now save the file name to the DB myArticle.EmbeddedVideo = vid.FileName; } else { myArticle.EmbeddedVideo = ""; } try { // If the article has some segments set if (!string.IsNullOrEmpty(myArticle.Segments)) { var oldSegments = myArticle.Segments.Split("|"); //Even though it is an edit we are resetting the order to 1...its waaay to complicated otherwise. myArticle.Segments = CreateSegmentsStringWithOrder1ButWithCheckToMakeSureNotAt1Already(sa.SelectedSegments, oldSegments); } else //no existing segments { myArticle.Segments = CreateSegmentsStringWithOrder1ButWithCheckToMakeSureNotAt1Already(sa.SelectedSegments, null); } _context.Update(myArticle); await _context.SaveChangesAsync(); //update the selected article segments //DataAccessLayer dla = new DataAccessLayer(_context, _user.companyID); } catch (DbUpdateConcurrencyException) { if (!SegmentArticleExists(myArticle.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } else { // Article title already exists ModelState.AddModelError(string.Empty, "Article Title already exists - please choose something unique"); } } return(RedirectToAction("Edit", new { id = myArticle.ID })); }
public async Task <IActionResult> Create(CompanySegmentViewModel cps) { _user = _context.User.FirstOrDefault(p => p.EmailAddress == _userManager.GetUserAsync(User).GetAwaiter().GetResult().Email); _cpy = _context.Company.FirstOrDefaultAsync(m => m.ID == _user.CompanyID).GetAwaiter().GetResult(); var companyID = _cpy.ID; //Initialise a new companysegment var mySegment = new CompanySegment(); if (ModelState.IsValid) { //ID,Order,Title,CoverImage,CoverImageMobileFriendly,PublishDate,FinishDate,ClientName,ClientLogoImage,ThemeColor,StandardColor,Draft,Department,Tags mySegment.CompanyID = companyID; mySegment.Order = cps.Order ?? 1; mySegment.Title = cps.Title; mySegment.PublishDate = cps.PublishDate; mySegment.FinishDate = cps.FinishDate; mySegment.ClientName = cps.ClientName; mySegment.ThemeColor = cps.ThemeColor; mySegment.StandardColor = cps.StandardColor; mySegment.Draft = DateTime.Now > cps.PublishDate ? false : true; mySegment.Department = cps.Department; mySegment.Tags = cps.Tags; mySegment.ClientName = cps.ClientName ?? _user.Name; IFormFile coverImage = cps.CoverImage; if (coverImage != null) { await _dla.UploadFileToS3(coverImage, _user.CompanyName + "_" + coverImage.FileName, "images/Uploads"); mySegment.CoverImage = coverImage.FileName; } IFormFile coverImageMB = cps.CoverImageMobileFriendly; if (coverImageMB != null) { await _dla.UploadFileToS3(coverImageMB, _user.CompanyName + "_" + coverImageMB.FileName, "images/Uploads"); //var filePath = Path.Combine(_rootpath, "images/Uploads", _user.companyName + "_" + coverImageMB.FileName); //using (var stream = new FileStream(filePath, FileMode.Create)) //{ // await coverImageMB.CopyToAsync(stream); //} //The file has been saved to disk - now save the file name to the DB mySegment.CoverImageMobileFriendly = coverImageMB.FileName; } IFormFile cli = cps.ClientLogoImage; if (cli != null) { await _dla.UploadFileToS3(cli, _user.CompanyName + "_" + cli.FileName, "images/Uploads"); //The file has been saved to disk - now save the file name to the DB mySegment.CoverImageMobileFriendly = cli.FileName; } InsertAtOrder1(); _context.Add(mySegment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } DataAccessLayer dla = new DataAccessLayer(_context); cps.Departments = dla.GetDepartments(companyID); return(View(cps)); }