protected void btnSave_Click(object sender, EventArgs e) { using (var _db = new Kronika106.Models.Kronika106DBContext()) { string userId = Context.User.Identity.Name; ApplicationUser aUser = _db.Users.FirstOrDefault(u => u.UserName == userId); aUser.SendMail = chSendMail.Checked; _db.SaveChanges(); } }
//public int LoginsCount { get; set; } protected void Page_Load() { if (!Context.User.Identity.IsAuthenticated) { Response.Redirect(GlobalConstants.urlDefault); } SuccesMessage.Visible = false; if (!IsPostBack) { var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>(); string userId = Context.User.Identity.Name; ApplicationUser aUser = null; using (var _db = new Kronika106.Models.Kronika106DBContext()) { aUser = _db.Users.FirstOrDefault(u => u.UserName == userId); } if (aUser != null) { email.Text = aUser.Email; firstame.Text = aUser.FirstName; lastname.Text = aUser.LastName; nick.Text = aUser.ScoutNickName; chSendMail.Checked = aUser.SendMail; if (!string.IsNullOrEmpty(aUser.PasswordHash)) { ChangePassword.Visible = true; } else { ChangePassword.Visible = false; } // Render success message var message = Request.QueryString["m"]; if (message != null) { // Strip the query string from action Form.Action = ResolveUrl("~/Account/Manage"); SuccessMessage = message == "ChangePwdSuccess" ? "Tvoje heslo bolo zmenené." : message == "SetPwdSuccess" ? "Tvoje heslo bolo nastavené." : message == "RemoveLoginSuccess" ? "Účet bol odstránený." : String.Empty; SuccesMessage.Visible = !String.IsNullOrEmpty(SuccessMessage); } } else { Response.Redirect(GlobalConstants.urlDefault); } } }
/// <summary> /// Vráti všetky fotkove komentáre pre danú akciu /// </summary> /// <returns> vrati html sranku s komentarmi</returns> public void GetComments(List <PageContent> contentList = null) { string trueEvetId = null;; if (forumType != ForumType.CommentList) { if (string.IsNullOrEmpty(Request.QueryString["ID"])) { } trueEvetId = Server.UrlDecode(Request.QueryString["ID"]); if (string.IsNullOrEmpty(trueEvetId)) { return; } trueEvetId = trueEvetId.ToLower(); } //len na kratko do DB if (forumType != ForumType.CommentList) { using (var _db = new Kronika106.Models.Kronika106DBContext()) { contentList = (from EventComments comment in _db.Forum where comment.RootID == null && ((comment.EventId.ToLower() == trueEvetId && ((forumType == ForumType.CommentList) || (forumType == ForumType.EventPhotoGallery) == comment.IsPhoto) && (((forumType == ForumType.Event) == comment.IsEvent) && ((forumType == ForumType.EventVideoGallery) == comment.IsVideo)))) orderby comment.ID descending select new PageContent { ID = comment.ID, CreatedUTC = comment.CreatedUTC, EventId = comment.EventId, RootID = comment.RootID, ThumbPath = comment.ThumbPath, ScoutNickName = comment.ApplicationUser.ScoutNickName, NickName = comment.ApplicationUser.NickName, Comment = comment.Comment, IsVideo = comment.IsVideo, IsEvent = comment.IsEvent, IsPhoto = comment.IsPhoto, UserID = comment.ApplicationUser.Id, UserName = comment.ApplicationUser.UserName /*, VideoPosition= comment.VideoPosition */ }).ToList(); } } if (contentList.Count > 0) { // resultHtml.Append("<div class=\"inner-content\">"); if (forumMode == ForumMode.Append) { phComments.InnerHtml += generateCommentTreeHTML(contentList, CommentLevel.Root); } else { phComments.InnerHtml = generateCommentTreeHTML(contentList, CommentLevel.Root); } } commentsContainer.Visible = true; if (string.IsNullOrWhiteSpace(phComments.InnerHtml)) { commentsContainer.Visible = false; } }
/// <summary> /// vrati skautsku prezyvku alebo nick /// </summary> /// <returns></returns> protected string GetUserNick() { string userId = Context.User.Identity?.Name; if (string.IsNullOrEmpty(userId)) { LogOutAll(); Response.Redirect(GlobalConstants.urlDefault); Session[GlobalConstants.UserNick] = null; return(null); } if (!IsPostBack) { if (Context.User.Identity.IsAuthenticated) { if (Session[GlobalConstants.UserNick] == null) { using (var _db = new Kronika106.Models.Kronika106DBContext()) { IEnumerable <UserNick> query = from ApplicationUser usr in _db.Users where usr.UserName == userId select new UserNick { FirstName = usr.FirstName, ScoutNickName = usr.ScoutNickName }; UserNick userData = query?.FirstOrDefault(); if (userData == null) { LogOutAll(); Response.Redirect(GlobalConstants.urlDefault); Session[GlobalConstants.UserNick] = null; return(null); } if (!string.IsNullOrEmpty(userData?.ScoutNickName)) { Session.Add(GlobalConstants.UserNick, userData?.ScoutNickName); } else { Session.Add(GlobalConstants.UserNick, userData?.FirstName); } } } } else { Session.Remove(GlobalConstants.UserNick); } } string val = (string)Session[GlobalConstants.UserNick]; return(val); }
public List <UserRecord> LoadUsers() { IEnumerable <UserRecord> query = null; using (var _db = new Kronika106.Models.Kronika106DBContext()) { query = from ApplicationUser usr in _db.Users where usr.EmailConfirmed == true orderby usr.ScoutNickName ascending, usr.FirstName ascending select new UserRecord { UserId = usr.Id, FirstName = usr.FirstName, LastName = usr.LastName, ScoutNickName = usr.ScoutNickName, Comments = usr.Comments.Count }; if (query != null && query.Count() > 0) { return(query.ToList()); } } return(null); }
public List <UserRecord> LoadSearch() { IEnumerable <UserRecord> query = null; using (var _db = new Kronika106.Models.Kronika106DBContext()) { query = from StatisticsSearch sch in _db.StatisticsSearch select new UserRecord { FirstName = sch.ApplicationUser.FirstName, LastName = sch.ApplicationUser.LastName, ScoutNickName = sch.ApplicationUser.ScoutNickName, SearchPattrern = sch.SearchPattern }; if (query != null && query.Count() > 0) { return(query.ToList()); } } return(null); }
public List <UserRecord> LoadUsers() { IEnumerable <UserRecord> query = null; using (var _db = new Kronika106.Models.Kronika106DBContext()) { query = from ApplicationUser usr in _db.Users select new UserRecord { FirstName = usr.FirstName, LastName = usr.LastName, ScoutNickName = usr.ScoutNickName, SendNewsMail = usr.SendMail, Email = usr.Email, EmailConfirmed = usr.EmailConfirmed, Comments = usr.Comments.Count, LastLogin = usr.LastLogInUTC, LoginCount = usr.LoginCount }; if (query != null && query.Count() > 0) { return(query.ToList()); } } return(null); }
public List <UserRecord> LoadBrowse() { IEnumerable <UserRecord> query = null; using (var _db = new Kronika106.Models.Kronika106DBContext()) { query = from StatisticBrowse sch in _db.StatisticBrowse orderby sch.CreatedUTC descending select new UserRecord { FirstName = sch.ApplicationUser.FirstName, LastName = sch.ApplicationUser.LastName, ScoutNickName = sch.ApplicationUser.ScoutNickName, BrowseURL = sch.Url, LastAccess = sch.CreatedUTC }; if (query != null && query.Count() > 0) { return(query.ToList()); } } return(null); }
protected void Page_Load(object sender, EventArgs e) { try { title.InnerText = "Najnovšie komentáre"; //kontrola ci je user prihlaseny Session[GlobalConstants.RedirectURLKey] = HttpContext.Current.Request.Url.PathAndQuery; if (!Context.User.Identity.IsAuthenticated) { Response.Redirect(GlobalConstants.urlForbidden, true); return; } if (!IsPostBack) { //prve nacitanie if (Session[GlobalConstants.LoadedCommentsCount] == null) { Session[GlobalConstants.LoadedCommentsCount] = 0; } //if (Session[GlobalConstants.MaxId] == null) { Session[GlobalConstants.MaxId] = 0; } int loadFirstCount = (int)Session[GlobalConstants.LoadedCommentsCount]; Session[GlobalConstants.LoadedCommentsCount] = 0; if (loadFirstCount > 0) { using (var _db = new Kronika106.Models.Kronika106DBContext()) { int maxId = (int)Session[GlobalConstants.MaxId]; int newComments = _db.Forum.Count(c => c.ID > maxId); } } ForumControll.ContentList.AddRange(LoadComments(0, loadFirstCount > pageSize ? loadFirstCount : pageSize)); } } catch (ThreadAbortException) { } }
public async void Unnamed_Click(object sender, EventArgs e) { try { progress.Text = ""; ErrorMessage.Visible = false; InfoMessage.Visible = false; using (var _db = new Kronika106.Models.Kronika106DBContext()) { IEnumerable <string> query = from ApplicationUser usr in _db.Users where (usr.SendMail || chSendToAll.Checked) && usr.EmailConfirmed select usr.Email; if (query == null || query.Count() == 0) { ErrorMessage.Visible = true; FailtureTextContent.Text = "Neexistujú užívatelia, ktorí odoberajú info maily"; return; } EmailService emailService = new EmailService(); foreach (var val in query) { await emailService.SendAsync(new Microsoft.AspNet.Identity.IdentityMessage() { Subject = subject.Text, Body = body.Text, Destination = (string)val }); progress.Text = progress.Text + string.Format("Mail pre: {0} odoslaný{1}", (string)val, Environment.NewLine); } InfoMessage.Visible = true; InfoTextContent.Text = "Maily boli odoslané"; subject.Text = ""; body.Text = ""; } } catch (Exception ex) { ExceptionUtility.LogException(ex, "AdminMaster"); ErrorMessage.Visible = true; FailtureTextContent.Text = ex.Message; } }
protected void Unnamed_Click(object sender, EventArgs e) { const int yeH = 266; const int yeW = 472; const double eventPhotoScalePercentage = 0.7; // /100 using (var _db = new Kronika106.Models.Kronika106DBContext()) { contentList = (from EventComments comment in _db.Forum //(comment.EventId.ToLower() == trueEvetId && ((forumType == ForumType.Event && comment.IsEvent) || (forumType == ForumType.EventPhotoGallery && comment.IsPhoto && comment.ThumbPath.Contains(photoName)))) orderby comment.ID ascending select new PageContent { ID = comment.ID, CreatedUTC = comment.CreatedUTC, EventId = comment.EventId, RootID = comment.RootID, ThumbPath = comment.ThumbPath, ScoutNickName = comment.ApplicationUser.ScoutNickName, NickName = comment.ApplicationUser.NickName, Comment = comment.Comment, IsVideo = comment.IsVideo, IsEvent = comment.IsEvent, IsPhoto = comment.IsPhoto, UserID = comment.ApplicationUser.Id, UserName = comment.ApplicationUser.UserName /*, VideoPosition= comment.VideoPosition */ }).ToList(); } if (contentList == null || contentList.Count == 0) { return; } string now = DateTime.Now.ToString("yyyyMMddHHmmss"); string pthAppData = Server.MapPath("..\\App_Data"); string pthAllPhotos = Server.MapPath("..\\AllPhotos"); DirectoryInfo dAllPhotosInfo = new DirectoryInfo(pthAllPhotos); List <string> lstDocFiles = new List <string>(); foreach (var dYear in dAllPhotosInfo.GetDirectories()) { //rok //DateTime.Now.ToString("yyyyMMddHHmmss") string fileName = $"kronika106_{dYear.Name}_{now}.docx"; string fileFullPath = System.IO.Path.Combine(pthAppData, fileName); doc = DocX.Create(fileFullPath); doc.InsertSection(); doc.InsertParagraph(dYear.Name, false, formatYear).Heading(HeadingType.Heading1).SpacingAfter(25d).Alignment = Alignment.center; var yImage = doc.AddImage(Path.Combine(dYear.FullName, GlobalConstants.fnRokFotka)); var pYImageYear = doc.InsertParagraph(); pYImageYear.AppendPicture(yImage.CreatePicture(yeH, yeW)).SpacingAfter(20d).Alignment = Alignment.center; var yPopisPath = Path.Combine(dYear.FullName, GlobalConstants.fnRokPopis); if (System.IO.File.Exists(yPopisPath)) { doc.InsertParagraph(System.IO.File.ReadAllText(yPopisPath), false, formatText).SpacingAfter(20d).Alignment = Alignment.both; } doc.InsertSectionPageBreak(); //toto rozdelit na zanostatny paragraf pre obrazok a pre text foreach (var dAkcia in dYear.GetDirectories()) { doc.InsertParagraph(dAkcia.Name, false, formatAkcia).Heading(HeadingType.Heading2).SpacingAfter(15d).Alignment = Alignment.center; string eventImagePath = Path.Combine(dAkcia.FullName, GlobalConstants.fnAkciaFotka); if (File.Exists(eventImagePath)) { var pImageEvent = doc.InsertParagraph(); var yImageEvent = doc.AddImage(eventImagePath); pImageEvent.AppendPicture(yImageEvent.CreatePicture(yeH, yeW)).SpacingAfter(15d).Alignment = Alignment.center; } string eventDescriptionPath = Path.Combine(dAkcia.FullName, GlobalConstants.fnAkciaPopis); if (File.Exists(eventDescriptionPath)) { doc.InsertParagraph(File.ReadAllText(eventDescriptionPath), false, formatText).SpacingAfter(15d).Alignment = Alignment.both; } string dbEventId = dAkcia.FullName.Replace(pthAllPhotos, "").TrimStart('\\').Replace("\\", "/"); commentTree(dbEventId, null, ref doc, ForumType.Event); //precitat fotky: foreach (var ePhoto in dAkcia.GetFiles("*.jpg")) { //vynechame uvodny obrazok if (ePhoto.Name.Equals(GlobalConstants.fnAkciaFotka)) { continue; } var pPhotoEvent = doc.InsertParagraph(); var yPhotoEvent = doc.AddImage(ePhoto.FullName); var pct = yPhotoEvent.CreatePicture(); pct.Width = (int)Math.Round(pct.Width * eventPhotoScalePercentage, 0); pct.Height = (int)Math.Round(pct.Height * eventPhotoScalePercentage, 0); pPhotoEvent.AppendPicture(pct).SpacingAfter(5d).SpacingBefore(8d).Alignment = Alignment.center; //tu najst podla nazvu akcie a fotky komnetare a doplmnit -usera commentTree(dbEventId, ePhoto.Name, ref doc, ForumType.EventPhotoGallery); } doc.InsertSectionPageBreak(); } doc.Save(); lstDocFiles.Add(fileFullPath); } string zipFileName = Path.Combine(pthAppData, $"Kronika2Word_{now}.zip"); createZipFile(zipFileName, lstDocFiles); //mama zip zmazeme foreach (var file in lstDocFiles) { System.IO.File.Delete(file); } //upload na klienta FileInfo fInfo = new FileInfo(zipFileName); Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.AddHeader("Content-Disposition", "attachment; filename=" + fInfo.Name); Response.AddHeader("Content-Length", fInfo.Length.ToString()); Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; Response.Flush(); Response.TransmitFile(fInfo.FullName); Response.End(); foreach (var file in lstDocFiles) { System.IO.File.Delete(file); } }
private string generateCommentTreeHTML(List <PageContent> lstCommnet, CommentLevel commentLevel) { StringBuilder resBuilder = new StringBuilder(); foreach (var comment in lstCommnet) { resBuilder.AppendFormat(htmlRow, comment.ID); resBuilder.Append(htmlFormGroup); switch (commentLevel) { case CommentLevel.Root: resBuilder.Append(hrmlColmd12); break; case CommentLevel.Reply: resBuilder.Append(hrmlColmd11_colmdoffset1); break; case CommentLevel.ReplyToReply: resBuilder.Append(hrmlColmd10_colmdoffset2); break; default: { resBuilder.Append(commentLevel); } break; } string eventId = null; string url = null; //linky sa generuju len ked pride na vstup uz list komentarov if (!string.IsNullOrEmpty(comment.EventId) && forumType == ForumType.CommentList) { string[] eventIdParams = comment.EventId.Split(GlobalConstants.EventIdSeparator, StringSplitOptions.RemoveEmptyEntries); if (comment.IsEvent && eventIdParams.Length == 2) { eventId = $"{eventIdParams[0]} {eventIdParams[1]}"; url = $"AkciaPopis.aspx?{QueryStringHelper.KeyID}={HttpUtility.UrlEncode(comment.EventId)}&{QueryStringHelper.KeyCommentId}=comment_{comment.ID}"; } if (comment.IsPhoto && eventIdParams.Length == 2) { eventId = $"{eventIdParams[0]} {eventIdParams[1]} galéria"; url = $"Akcia.aspx?{QueryStringHelper.KeyID}={HttpUtility.UrlEncode(comment.EventId)}&{QueryStringHelper.KeyCommentId}=comment_{comment.ID}"; } if (comment.IsVideo && eventIdParams.Length == 4) { eventId = $"{eventIdParams[0]} {eventIdParams[1]} {eventIdParams[3]}"; url = $"Video.aspx?{QueryStringHelper.KeyID}={HttpUtility.UrlEncode(comment.EventId)}&{QueryStringHelper.KeyCommentId}=comment_{comment.ID}"; } if (comment.IsFileSystem) { switch (eventIdParams.Length) { case 1: //rok eventId = $"Rok {eventIdParams[0]}"; url = $"RokAkcie.aspx?{QueryStringHelper.KeyID}={HttpUtility.UrlEncode(comment.EventId)}"; break; case 2: //akcia eventId = $"Rok {eventIdParams[0]}, akcia {eventIdParams[1]}"; url = $"AkciaPopis.aspx?{QueryStringHelper.KeyID}={HttpUtility.UrlEncode(comment.EventId)}"; break; case 4: //video eventId = $"Rok {eventIdParams[0]}, akcia {eventIdParams[1]}, video {eventIdParams[3]}"; url = $"Video.aspx?{QueryStringHelper.KeyID}={HttpUtility.UrlEncode(comment.EventId)}"; break; default: break; } } } string user = string.Format("<strong>{0}</strong> {1} {2}", (!string.IsNullOrEmpty(comment.ScoutNickName) ? comment.ScoutNickName : comment.NickName), !comment.IsFileSystem ? CommonLogic.ToSKDateTime(comment.CreatedUTC) : string.Empty, string.Format("<a href=\"{0}\">{1}</a>", url, eventId)); string picture = null; if (!string.IsNullOrEmpty(comment.ThumbPath)) { picture = string.Format(image, comment.ThumbPath); } string replyLink = null; if (commentLevel != CommentLevel.ReplyToReply && forumType != ForumType.CommentList) { replyLink = string.Format(htmlReplyLink, comment.ID); } string editLink = null; string deleteLink = null; if (comment.UserName == Context.User.Identity.Name && forumType != ForumType.CommentList) { editLink = string.Format(htmlEditLink, comment.ID); deleteLink = string.Format(htmlDeleteLink, comment.ID); } resBuilder.AppendFormat(htmlComment, comment.ID, user, replyLink, picture, editLink, deleteLink); resBuilder.AppendLine(comment.Comment); resBuilder.AppendLine(htmlEndP); resBuilder.AppendLine(htmlEndDiv); resBuilder.AppendLine(htmlEndDiv); resBuilder.AppendLine(htmlEndDiv); if (forumType != ForumType.CommentList) { List <PageContent> lstChild = null; using (var _db = new Kronika106.Models.Kronika106DBContext()) { lstChild = (from EventComments childComment in _db.Forum where childComment.RootID == comment.ID orderby comment.ID descending select new PageContent { ID = childComment.ID, CreatedUTC = childComment.CreatedUTC, EventId = childComment.EventId, RootID = childComment.RootID, ThumbPath = childComment.ThumbPath, ScoutNickName = childComment.ApplicationUser.ScoutNickName, NickName = childComment.ApplicationUser.NickName, Comment = childComment.Comment, IsVideo = childComment.IsVideo, IsEvent = comment.IsEvent, IsPhoto = comment.IsPhoto, UserID = childComment.ApplicationUser.Id, UserName = childComment.ApplicationUser.UserName /*, VideoPosition= comment.VideoPosition */ }).ToList(); } if (lstChild.Count > 0) { resBuilder.AppendLine(generateCommentTreeHTML(lstChild, commentLevel + 1)); } } //else //{ // resBuilder.AppendLine(htmlHr); //} } return(resBuilder.ToString()); }
public List <ForumControll.PageContent> LoadComments(int skip, int recordCount) { string userID = string.Empty; if (Request.QueryString.Count == 1) { userID = Request.QueryString["ID"]; using (var _db = new Kronika106.Models.Kronika106DBContext()) { //ak nie je uvedene user id idem vzdy na komentare usera, alebo ak niekto zmanipuluje user id var user = string.IsNullOrWhiteSpace(userID) ? null : _db.Users.FirstOrDefault(u => u.Id == userID); if (user == null) { user = _db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); //paranoid mode - toto by malo byt v DB vzdy userID = user?.Id; } //paranoid mode - user id bude naplnene vzdy if (!string.IsNullOrWhiteSpace(userID)) { title.InnerText = "Komentáre " + (!string.IsNullOrEmpty(user.ScoutNickName) ? user.ScoutNickName : $"{user.FirstName} {user.LastName}"); } } //nastavenie user ID } List <ForumControll.PageContent> commentList = null; using (var _db = new Kronika106.Models.Kronika106DBContext()) { int allCommentsCount = _db.Forum.Count(); commentList = (from EventComments events in _db.Forum where (userID != null && events.ApplicationUser.Id == userID) || (userID == string.Empty) orderby events.CreatedUTC descending select new ForumControll.PageContent { ID = events.ID, NickName = events.ApplicationUser.NickName, ScoutNickName = events.ApplicationUser.ScoutNickName, EventId = events.EventId, Comment = events.Comment, CreatedUTC = events.CreatedUTC, ThumbPath = events.ThumbPath, IsEvent = events.IsEvent, IsPhoto = events.IsPhoto, IsVideo = events.IsVideo, RootID = events.RootID }).Skip(skip).Take(recordCount > maxCommentCount ? maxCommentCount : recordCount).ToList(); } if (commentList != null && commentList.Count() > 0) { Session[GlobalConstants.LoadedCommentsCount] = (int)Session[GlobalConstants.LoadedCommentsCount] + commentList.Count(); StringBuilder resultHtml = new StringBuilder(); int maxId = 0; maxId = commentList.Max(c => c.ID); Session[GlobalConstants.MaxId] = maxId; btnLoadNextComments.Enabled = true; // phComments.InnerHtml = phComments.InnerHtml + fc.GenerateCommentTreeHTML(commentList, ForumControll.CommentLevel.Root); } else { btnLoadNextComments.Enabled = false; } return(commentList); }