public ActionResult FromDate(int?id, DateAndTime model) { var fromDate = model.GetDateTime(); if (fromDate < DateTime.UtcNow.ToUkTimeFromUtc().AddMinutes(15)) { ModelState.AddModelError("Hour", "Start time must be at least 15 minutes from now"); ModelState.AddModelError("Minute", string.Empty); } if (DatesOverlapExistingSlip(MPID, fromDate)) { ModelState.AddModelError("Date", "You have already submitted a slip for this date"); } if (ModelState.IsValid) { if (id.HasValue) { // Update an existing record SlippingRequest slippingRequest = Get(id.Value); if (slippingRequest != null && !IsSubmitted(slippingRequest)) { slippingRequest.FromDate = model.GetDateTime(); CreateOrUpdate(slippingRequest); return(RedirectToAction("ToDate", new { id })); } else { return(RedirectToAction("NotFound", "Home")); } } else { // Create a new record SlippingRequest slippingRequest = new SlippingRequest() { FromDate = model.GetDateTime() }; int requestId = CreateOrUpdate(slippingRequest); return(RedirectToAction("ToDate", new { id = requestId })); } } else { return(View(model)); } }
public virtual ActionResult Add(AddPageModel pageModel) { var newPage = new Page { Body = pageModel.Body.ToSafeHtml(), CommentStatus = pageModel.CommentStatus, CreatedDate = DateAndTime.GetDateTime(), Keyword = pageModel.Keyword, Order = pageModel.Order, Parent = _pageSerivce.Find(pageModel.ParentId.Value), Status = pageModel.Status, Title = pageModel.Title, User = _userService.Find(User.Identity.Name), Description = pageModel.Description }; _pageSerivce.Add(newPage); _uow.SaveChanges(); return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "برگه جدید با موفقیت در سیستم ثبت شد", Mode = AlertMode.Success })); }
protected void Application_AuthenticateRequest(Object sender, EventArgs e) { var context = DependencyResolver.Current.GetService <HttpContextBase>(); var principalService = ObjectFactory.GetInstance <IPrincipalService>(); //DependencyResolver.Current.GetService<IPrincipalService>(); var formsAuthenticationService = ObjectFactory.GetInstance <IFormsAuthenticationService>(); // Set the HttpContext's User to our IPrincipal context.User = principalService.GetCurrent(); if (!context.User.Identity.IsAuthenticated) { return; } var userService = ObjectFactory.GetInstance <IUserService>(); UserStatus userStatus = userService.GetStatus(Context.User.Identity.Name); if (userStatus.IsBaned || !context.User.IsInRole(userStatus.Role)) { formsAuthenticationService.SignOut(); } var dbContext = ObjectFactory.GetInstance <IUnitOfWork>(); userService.UpdateUserLastActivity(User.Identity.Name, DateAndTime.GetDateTime()); dbContext.SaveChanges(); }
public void DeActiveUser(int id) { User selectedUser = _users.Find(id); selectedUser.IsBaned = true; selectedUser.BanedDate = DateAndTime.GetDateTime(); }
public virtual ActionResult Add(AddUpdateArticleModel model) { _articleService.Add(new Article { Body = model.Body.ToSafeHtml(), Category = _categoryService.Find(model.CategoryId), CommentStatus = model.CommentStatus, CreatedDate = DateAndTime.GetDateTime(), Description = model.Description, Keyword = model.Keywords, LikeCount = 0, Status = model.ArticleStatus, Title = model.Title, User = _userService.Find(User.Identity.Name), VisitedCount = 0, }); _uow.SaveChanges(); return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "مطلب جدید با موفقیت در سیستم ثبت شد", Mode = AlertMode.Success })); }
public EditedUserStatus UpdateProfile(EditProfileModel userModel) { EditedUserStatus result; if (ExistsByEmail(userModel.Email) && !GetUserNameByEmail(userModel.Email).Equals(userModel.UserName)) { result = EditedUserStatus.EmailExist; } else { User selectedUser = _users.FirstOrDefault(user => user.UserName.Equals(userModel.UserName)); selectedUser.Email = userModel.Email; selectedUser.UserMetaData.FirstName = userModel.FirstName; selectedUser.UserMetaData.LastName = userModel.LastName; selectedUser.UserMetaData.Major = userModel.Major; selectedUser.UserMetaData.BirthDay = userModel.BirthDay; selectedUser.UserMetaData.Description = userModel.Description; if (!string.IsNullOrEmpty(userModel.NewPassword)) { selectedUser.Password = Encryption.EncryptingPassword(userModel.NewPassword); selectedUser.LastPasswordChange = DateAndTime.GetDateTime(); } result = EditedUserStatus.UpdatingUserSuccessfully; } return(result); }
public virtual ActionResult ResetPassword(string key) { if (_forgttenPasswordService.RequestDate(key).Subtract(DateAndTime.GetDateTime()).TotalDays > 1) { return(View()); } string newPass = new Random().Next(500000, 10000000).ToString(CultureInfo.InvariantCulture); User selectedUser = _forgttenPasswordService.FindUser(key); _forgttenPasswordService.Remove(key); selectedUser.Password = Encryption.EncryptingPassword(newPass); selectedUser.LastPasswordChange = DateAndTime.GetDateTime(); if (_emailService.SendNewPassword(selectedUser.UserName, selectedUser.Email, newPass) == SendingMailResult.Successful) { _uow.SaveChanges(); } else { ViewBag.Message = "متاسفانه خطایی در ارسال ایمیل رخ داده است."; return(View()); } ViewBag.Message = "کلمه عبور شما با موفقیت باز نشانی شد و به ایمیل شما ارسال گردید"; return(View()); }
public virtual ActionResult EditSlider(EditSliderModel SliderModel) { if (!ModelState.IsValid) { return(PartialView(MVC.Admin.Shared.Views._ValidationSummery)); } SliderModel.ModifiedDate = DateAndTime.GetDateTime(); SliderModel.EditedByUser = _userService.GetUserByUserName(User.Identity.Name); UpdateSliderStatus status = _SliderService.UpdateSlider(SliderModel); if (status == UpdateSliderStatus.Successfull) { _uow.SaveChanges(); return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "اطلاعات با موفقیت به روز رسانی شد", Mode = AlertMode.Success })); } return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "خطا در به روز رسانی اطلاعات", Mode = AlertMode.Error })); }
public void DeActiveUsers(int[] usersId) { foreach (User selectedUser in usersId.Select(id => _users.Find(id))) { selectedUser.IsBaned = true; selectedUser.BanedDate = DateAndTime.GetDateTime(); } }
public virtual ActionResult AddAnonymousArticleComment(AddAnonymousCommentModel model) { if (!ModelState.IsValid) { return(PartialView(MVC.Comment.Views._AddAnonymousPageComment, model)); } var newComment = new Comment { AddedDate = DateAndTime.GetDateTime(), Body = model.Body.ToSafeHtml(), LikeCount = 0 }; if (model.ReplyId != null) { newComment.Parent = _commentService.Find(model.ReplyId.Value); } newComment.AnonymousUser = new AnonymousUser { Email = model.Email, Name = model.Name, IP = Request.ServerVariables["REMOTE_ADDR"] }; newComment.Article = _articleService.Find(model.Id); _commentService.AddComment(newComment); _uow.SaveChanges(); if (model.ReplyId != null) { _emailService.SendCommentReplyNotification(new CommentReplyEmailNotificationData { CommentId = newComment.Id, CommentText = newComment.Body, FromUserName = model.Name, PostId = newComment.Article.Id, PostTitle = newComment.Article.Title, ToUserName = newComment.Parent.User.UserName, ToEmail = newComment.Parent.User.Email }, CommentReplyType.ReplyToArticleComment); } bool sendData = newComment.IsApproved = !_optionService.ModeratingComment; if (sendData) { return(Json(new { show = "true", name = model.Name, date = DateAndTime.ConvertToPersian(newComment.AddedDate), likeCount = ConvertToPersian.ConvertToPersianString(0), body = model.Body })); } return(Json(new { show = "false" })); }
public virtual ActionResult AddUser(AddUserModel userModel) { ModelState.Remove("BirthDay"); if (!ModelState.IsValid) { return(PartialView(MVC.Admin.Shared.Views._ValidationSummery)); } var newUser = new User { Email = userModel.Email, IP = Request.ServerVariables["REMOTE_ADDR"], Password = Encryption.EncryptingPassword(userModel.Password), CreatedDate = DateAndTime.GetDateTime(), Role = _roleService.GetRoleByRoleId(userModel.RoleId), UserName = userModel.UserName, UserMetaData = new UserMetaData { BirthDay = userModel.BirthDay, Description = userModel.Description, FirstName = userModel.FirstName, LastName = userModel.LastName, Major = userModel.Major, } }; AddUserStatus status = _userService.Add(newUser); string message; if (status == AddUserStatus.AddingUserSuccessfully) { message = "کاربر جدید با موفقیت در سیستم ثبت شد"; _uow.SaveChanges(); return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = message, Mode = AlertMode.Success })); } switch (status) { case AddUserStatus.EmailExist: message = "ایمیل وارد شده تکراری است"; break; case AddUserStatus.UserNameExist: message = "نام کاربری تکراری است"; break; default: message = "نام کاربری یا ایمیل تکراری است"; break; } return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Mode = AlertMode.Error, Message = message })); }
public ActionResult ToDate(int id, DateAndTime model) { SlippingRequest slippingRequest = Get(id); if (slippingRequest != null && !IsSubmitted(slippingRequest)) { DateTime toDate = model.GetDateTime(); if (toDate.Date < slippingRequest.FromDate.Date) { ModelState.AddModelError("Date", "Finish date cannot be before start date"); } if (toDate.Date == slippingRequest.FromDate.Date) { if (toDate.TimeOfDay <= slippingRequest.FromDate.TimeOfDay) { ModelState.AddModelError("Hour", "Finish time must be at least 15 minutes after start time"); ModelState.AddModelError("Minute", string.Empty); } } if (DatesOverlapExistingSlip(MPID, slippingRequest.FromDate, toDate)) { ModelState.AddModelError("Date", "The period you have selected overlaps with an existing slip you have submitted"); } if (ModelState.IsValid) { slippingRequest.ToDate = model.GetDateTime(); CreateOrUpdate(slippingRequest); return(RedirectToAction("Location", new { id })); } else { return(View(model)); } } else { return(RedirectToAction("NotFound")); } }
public ChangePasswordResult ChangePasswordByUserName(string username, string oldPassword, string newPassword) { User selectedUser = _users.FirstOrDefault(x => x.UserName.Equals(username)); if (!Encryption.VerifyPassword(oldPassword, selectedUser.Password)) { return(ChangePasswordResult.ChangedFaild); } selectedUser.Password = Encryption.EncryptingPassword(newPassword); selectedUser.LastPasswordChange = DateAndTime.GetDateTime(); return(ChangePasswordResult.ChangedSuccessfully); }
public ChangePasswordResult ChangePasswordByUserId(int Id, string oldPassword, string newPassword) { User selectedUser = _users.Find(Id); if (!Encryption.VerifyPassword(oldPassword, selectedUser.Password)) { return(ChangePasswordResult.ChangedFaild); } selectedUser.Password = Encryption.EncryptingPassword(newPassword); selectedUser.LastPasswordChange = DateAndTime.GetDateTime(); return(ChangePasswordResult.ChangedSuccessfully); }
public virtual ActionResult AddSlider(AddSliderModel SliderModel) { var lstSliderStatus = new List <SelectListItem> { new SelectListItem { Text = "عادی", Value = "visible", Selected = true }, new SelectListItem { Text = "پنهان", Value = "hidden" }, new SelectListItem { Text = "پیش نویس", Value = "draft" }, new SelectListItem { Text = "آرشیو", Value = "archive" } }; ViewBag.SliderStatus = lstSliderStatus; if (!ModelState.IsValid) { return(PartialView(MVC.Admin.Shared.Views._ValidationSummery)); } var Slider = new Slider { Priority = SliderModel.SliderPriority, CreatedDate = DateAndTime.GetDateTime(), Link = SliderModel.SliderLink, Picture = SliderModel.SliderPicture, Status = SliderModel.SliderStatus.ToString().ToLower(), Title = SliderModel.SliderTitle, EditedByUser = _userService.GetUserByUserName(User.Identity.Name) }; Slider.User = _userService.GetUserByUserName(User.Identity.Name); _SliderService.AddSlider(Slider); _uow.SaveChanges(); return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "اسلاید جدید با موقیت در سیستم ثبت شد", Mode = AlertMode.Success })); }
public virtual ActionResult Index(ForgottenPasswordModel model) { if (!ModelState.IsValid) { return(PartialView(MVC.ForgottenPassword.Views._Index, model)); } bool isEmailExist = _userService.ExistsByEmail(model.Email); if (isEmailExist) { User selecteduser = _userService.GetUserByEmail(model.Email); string key = Guid.NewGuid().ToString(); var newRequestTicket = new ForgottenPassword { User = selecteduser, Key = key, ResetDateTime = DateAndTime.GetDateTime() }; _forgttenPasswordService.Add(newRequestTicket); if (_emailService.SendResetPasswordConfirmationEmail(selecteduser.UserName, model.Email, key) == SendingMailResult.Successful) { _uow.SaveChanges(); } else { return(Json(new { result = "true", message = "متاسفانه خطایی در ارسال ایمیل رخ داده است." })); } return(Json(new { result = "true", message = "ایمیلی برای تایید بازنشانی کلمه عبور برای شما ارسال شد.اعتبارایمیل ارسالی 24 ساعت است." })); } return(Json(new { result = "false", message = "این ایمیل در سیستم ثبت نشده است" })); }
public virtual ActionResult Add(AddPageModel pageModel) { var newPage = new Page { Body = pageModel.Body.ToSafeHtml(), CommentStatus = pageModel.CommentStatus, CreatedDate = DateAndTime.GetDateTime(), Keyword = pageModel.Keyword, Order = pageModel.Order, Parent = _pageService.Find(pageModel.ParentId.Value), Status = pageModel.Status, Title = pageModel.Title, SubTitle = pageModel.SubTitle, IconClass = pageModel.IconClass, FeatureImage = pageModel.FeatureImage, ExternalLink = pageModel.ExternalLink, User = _userService.Find(User.Identity.Name), Description = pageModel.Description }; _pageService.Add(newPage); _uow.SaveChanges(); #region Indexing new Post by Lucene.NET //Index the new Post lucene.NET new LucenePageSearch(_pageService); Page currentPage = _pageService.Find(newPage.Id); LucenePageSearch.AddUpdateLuceneIndex(new LucenePageModel { SubTitle = currentPage.SubTitle, Body = HtmlUtility.RemoveHtmlTags(currentPage.Body), Description = currentPage.Description, Keywords = currentPage.Keyword, PageId = currentPage.Id, Title = currentPage.Title }); #endregion return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "صفحه جدید با موفقیت در سیستم ثبت شد", Mode = AlertMode.Success })); }
public virtual ActionResult Edit(EditPageModel pageModel) { var selectedPage = new Page { Body = pageModel.Body.ToSafeHtml(), CommentStatus = pageModel.CommentStatus, Description = pageModel.Description, EditedByUser = _userService.Find(User.Identity.Name), Keyword = pageModel.Keyword, ModifiedDate = DateAndTime.GetDateTime(), Id = pageModel.Id, Order = pageModel.Order, Parent = _pageService.Find(pageModel.ParentId.Value), Status = pageModel.Status, Title = pageModel.Title, SubTitle = pageModel.SubTitle, IconClass = pageModel.IconClass, FeatureImage = pageModel.FeatureImage, ExternalLink = pageModel.ExternalLink, }; _pageService.Update(selectedPage); _uow.SaveChanges(); #region Indexing updated book by Lucene.NET //Index updated book lucene.NET new LucenePageSearch(_pageService); LucenePageSearch.ClearLuceneIndexRecord(pageModel.Id); Page currentPage = _pageService.Find(pageModel.Id); LucenePageSearch.AddUpdateLuceneIndex(new LucenePageModel { SubTitle = currentPage.SubTitle, Body = HtmlUtility.RemoveHtmlTags(currentPage.Body), Description = currentPage.Description, Keywords = currentPage.Keyword, PageId = currentPage.Id, Title = currentPage.Title }); #endregion return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "صفحه مورد نظر با موفقیت ویرایش شد", Mode = AlertMode.Success })); }
protected void Application_AuthenticateRequest(Object sender, EventArgs e) { //try //{ var context = DependencyResolver.Current.GetService <HttpContextBase>(); var principalService = DependencyResolver.Current.GetService <IPrincipalService>(); // ObjectFactory.GetInstance<IPrincipalService>(); var formsAuthenticationService = DependencyResolver.Current.GetService <IFormsAuthenticationService>(); // Set the HttpContext's User to our IPrincipal context.User = principalService.GetCurrent(); if (!context.User.Identity.IsAuthenticated) { return; } var userService = DependencyResolver.Current.GetService <IUserService>(); UserStatus userStatus = userService.GetStatus(Context.User.Identity.Name); if (userStatus.IsBaned || !context.User.IsInRole(userStatus.Role)) { formsAuthenticationService.SignOut(); } var dbContext = DependencyResolver.Current.GetService <IUnitOfWork>(); userService.UpdateUserLastActivity(User.Identity.Name, DateAndTime.GetDateTime()); dbContext.SaveChanges(); //} //catch //{ // HttpRuntime.UnloadAppDomain(); // سبب ری استارت برنامه و آغاز مجدد آن با درخواست بعدی میشود // throw; //} }
private static VerifyUserStatus Verify(User selectedUser, string password) { var result = VerifyUserStatus.VerifiedFaild; bool verifiedPassword = Encryption.VerifyPassword(password, selectedUser.Password); if (!verifiedPassword) { return(result); } if (selectedUser.IsBaned) { result = VerifyUserStatus.UserIsbaned; } else { selectedUser.LastLoginDate = DateAndTime.GetDateTime(); result = VerifyUserStatus.VerifiedSuccessfully; } return(result); }
public virtual ActionResult Register(RegisterModel model) { if (!ModelState.IsValid) { return(PartialView(MVC.User.Views._Register, model)); } var newUser = new User { CreatedDate = DateAndTime.GetDateTime(), Email = model.Email, IP = Request.ServerVariables["REMOTE_ADDR"], IsBaned = false, UserName = model.UserName, Password = Encryption.EncryptingPassword(model.Password), UserMetaData = new UserMetaData(), Role = _roleService.GetRoleByRoleName("user"), LastLoginDate = DateAndTime.GetDateTime() }; AddUserStatus addingNewUserResult = _userService.Add(newUser); if (addingNewUserResult == AddUserStatus.EmailExist) { ModelState.AddModelError("", "ایمیل وارد شده قبلا درسیستم ثبت شده است."); return(PartialView(MVC.User.Views._Register, model)); } if (addingNewUserResult == AddUserStatus.UserNameExist) { ModelState.AddModelError("", "نام کاربری تکراری است."); return(PartialView(MVC.User.Views._Register, model)); } _uow.SaveChanges(); SetAuthCookie(model.UserName, "user", false); return(Json(new { result = "success" })); }
public virtual ActionResult Submit(ContactUsModel model) { if (!ModelState.IsValid || !this.IsCaptchaValid("Invalid captcha")) { return(PartialView(MVC.Shared.Views._ValidationSummery, model)); } _messageService.Add(new Message { AddedDate = DateAndTime.GetDateTime(), Body = model.Body.ToSafeHtml(), Subject = string.Format("{0} #[نام: ]{1}#[ایمیل: ]{2}#[تلفن: ]{3}#[نام شرکت: ]{4}#[واحد مربوطه: ]{5}#", model.Subject, model.Name, model.Email, model.Phone, model.CompanyName, model.Unit), IsAnswared = false, User = _userService.Find(User.Identity.Name) }); _uow.SaveChanges(); return(PartialView(MVC.Shared.Views._Alert, new Alert { Mode = AlertMode.Success, Message = "پیغام شما با موفقیت برای ما ارسال شد." })); }
public virtual ActionResult Submit(ContactUsModel model) { if (!ModelState.IsValid) { return(PartialView(MVC.Shared.Views._ValidationSummery, model)); } _messageService.Add(new Message { AddedDate = DateAndTime.GetDateTime(), Body = model.Body.ToSafeHtml(), Subject = model.Subject, IsAnswared = false, User = _userService.Find(User.Identity.Name) }); _uow.SaveChanges(); return(PartialView(MVC.Shared.Views._Alert, new Alert { Mode = AlertMode.Success, Message = "پیغام شما با موفقیت برای ما ارسال شد." })); }
public virtual ActionResult Edit(AddUpdateArticleModel model) { var selectedArticle = new Article { Body = model.Body.ToSafeHtml(), Category = _categoryService.Find(model.CategoryId), CommentStatus = model.CommentStatus, Description = model.Description, EditedByUser = _userService.Find(User.Identity.Name), Id = model.Id, Keyword = model.Keywords, ModifiedDate = DateAndTime.GetDateTime(), Status = model.ArticleStatus, Title = model.Title, }; _articleService.Update(selectedArticle); _uow.SaveChanges(); return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "مطلب مورد نظر با موفقیت ویرایش شد", Mode = AlertMode.Success })); }
protected void Application_AuthenticateRequest(Object sender, EventArgs e) { var principalService = SmObjectFactory.Container.GetInstance<IPrincipalService>(); // Set the HttpContext's User to our IPrincipal Context.User = principalService.GetCurrent(); if (Context.User == null) return; if (!Context.User.Identity.IsAuthenticated) return; var userService = SmObjectFactory.Container.GetInstance<IUserService>(); var userStatus = userService.GetStatus(Context.User.Identity.Name); if (userStatus.IsBaned || !Context.User.IsInRole(userStatus.Role)) { var formsAuthenticationService = SmObjectFactory.Container.GetInstance<IFormsAuthenticationService>(); formsAuthenticationService.SignOut(); } var dbContext = SmObjectFactory.Container.GetInstance<IUnitOfWork>(); userService.UpdateUserLastActivity(User.Identity.Name, DateAndTime.GetDateTime()); dbContext.SaveChanges(); }
public virtual ActionResult Edit(EditPageModel pageModel) { var selectedPage = new Page { Body = pageModel.Body.ToSafeHtml(), CommentStatus = pageModel.CommentStatus, Description = pageModel.Description, EditedByUser = _userService.Find(User.Identity.Name), Keyword = pageModel.Keyword, ModifiedDate = DateAndTime.GetDateTime(), Id = pageModel.Id, Order = pageModel.Order, Parent = _pageSerivce.Find(pageModel.ParentId.Value), Status = pageModel.Status, Title = pageModel.Title }; _pageSerivce.Update(selectedPage); _uow.SaveChanges(); return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "برگه مورد نظر با موفقیت ویرایش شد", Mode = AlertMode.Success })); }
public virtual ActionResult AddUserPostComment(AddUserCommentModel model) { if (!ModelState.IsValid) { return(PartialView(MVC.Comment.Views._AddUserPostComment, model)); } var newComment = new Comment { AddedDate = DateAndTime.GetDateTime(), Body = model.Body.ToSafeHtml(), LikeCount = 0 }; if (model.ReplyId != null) { newComment.Parent = _commentService.Find(model.ReplyId.Value); } newComment.User = _userService.Find(User.Identity.Name); bool sendData = newComment.IsApproved = !_optionService.ModeratingComment; newComment.Post = _postService.Find(model.Id); _commentService.AddComment(newComment); _uow.SaveChanges(); if (model.ReplyId != null) { string toUserName; string toEmail; if (newComment.Parent.User != null) { toUserName = newComment.Parent.User.UserName; toEmail = newComment.Parent.User.Email; } else { toUserName = newComment.Parent.AnonymousUser.Name; toEmail = newComment.Parent.AnonymousUser.Email; } _emailService.SendCommentReplyNotification(new CommentReplyEmailNotificationData { CommentId = newComment.Id, CommentText = newComment.Body, FromUserName = newComment.User.UserName, PostId = newComment.Post.Id, PostTitle = newComment.Post.Title, ToUserName = toUserName, ToEmail = toEmail }, CommentReplyType.ReplyToPostComment); } if (sendData) { return(Json(new { show = "true", name = User.Identity.Name, date = DateAndTime.ConvertToPersian(DateAndTime.GetDateTime()), likeCount = ConvertToPersian.ConvertToPersianString(0), body = model.Body })); } return(Json(new { show = "false" })); }
public virtual ActionResult EditPost(EditPostModel postModel) { if (!ModelState.IsValid) { return(PartialView(MVC.Admin.Shared.Views._ValidationSummery)); } postModel.ModifiedDate = DateAndTime.GetDateTime(); postModel.EditedByUser = _userService.GetUserByUserName(User.Identity.Name); postModel.Labels = _labelService.GetLabelsById(postModel.LabelsId); // _downloadLinkService.RemoveByPostId(postModel.PostId); _uow.SaveChanges(); //if (!string.IsNullOrEmpty(postModel.Links.DownloadLink1.Link)) //{ // postModel.DownloadLinks.Add(postModel.Links.DownloadLink1); //} //if (!string.IsNullOrEmpty(postModel.Links.DownloadLink2.Link)) //{ // postModel.DownloadLinks.Add(postModel.Links.DownloadLink2); //} //if (!string.IsNullOrEmpty(postModel.Links.DownloadLink3.Link)) //{ // postModel.DownloadLinks.Add(postModel.Links.DownloadLink3); //} //if (!string.IsNullOrEmpty(postModel.Links.DownloadLink4.Link)) //{ // postModel.DownloadLinks.Add(postModel.Links.DownloadLink4); //} //postModel.Book.Description = postModel.Book.Description.ToSafeHtml(); postModel.PostBody = postModel.PostBody.ToSafeHtml(); UpdatePostStatus status = _postService.UpdatePost(postModel); if (status == UpdatePostStatus.Successfull) { _uow.SaveChanges(); #region Indexing updated Post by Lucene.NET new LucenePostSearch(_postService); //Index updated book lucene.NET LucenePostSearch.ClearLuceneIndexRecord(postModel.PostId); Post currentPost = _postService.Find(postModel.PostId); LucenePostSearch.AddUpdateLuceneIndex(new LucenePostModel { Labels = string.Join(" , ", currentPost.Labels.Select(l => l.Name).ToArray()), Body = HtmlUtility.RemoveHtmlTags(currentPost.Body), Description = currentPost.Description, Keywords = currentPost.Keyword, PostId = currentPost.Id, Title = currentPost.Title }); #endregion return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "اطلاعات با موفقیت به روز رسانی شد", Mode = AlertMode.Success })); } return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "خطا در به روز رسانی اطلاعات", Mode = AlertMode.Error })); }
public virtual ActionResult AddPost(AddPostModel postModel) { if (!ModelState.IsValid) { return(PartialView(MVC.Admin.Shared.Views._ValidationSummery)); } postModel.PostBody = postModel.PostBody.ToSafeHtml(); //postModel.Book.Description = postModel.Book.Description.ToSafeHtml(); var post = new Post { Body = postModel.PostBody, CommentStatus = postModel.PostCommentStatus, CreatedDate = DateAndTime.GetDateTime(), Description = postModel.PostDescription, Keyword = postModel.PostKeyword, Picture = postModel.PostPicture, Status = postModel.PostStatus.ToString().ToLower(), Title = postModel.PostTitle, }; #region Comment //var book = new Book //{ // Author = postModel.Book.Author, // Description = postModel.Book.Description, // ISBN = postModel.Book.ISBN, // Language = postModel.Book.Language, // Name = postModel.Book.Name, // Year = postModel.Book.Year, // Publisher = postModel.Book.Publisher, // Page = postModel.Book.Page //}; //var bookImage = new BookImage //{ // Path = postModel.BookImage.Path, // Title = postModel.BookImage.Title, // Description = postModel.BookImage.Description, // UploadedDate = DateAndTime.GetDateTime() //}; //var links = new List<DownloadLink>(); //if (!string.IsNullOrEmpty(postModel.DownloadLinks.DownloadLink1.Link)) //{ // links.Add(postModel.DownloadLinks.DownloadLink1); //} //if (!string.IsNullOrEmpty(postModel.DownloadLinks.DownloadLink2.Link)) //{ // links.Add(postModel.DownloadLinks.DownloadLink2); //} //if (!string.IsNullOrEmpty(postModel.DownloadLinks.DownloadLink3.Link)) //{ // links.Add(postModel.DownloadLinks.DownloadLink3); //} //if (!string.IsNullOrEmpty(postModel.DownloadLinks.DownloadLink4.Link)) //{ // links.Add(postModel.DownloadLinks.DownloadLink4); //} //post.Book = book; //post.DownloadLinks = links; //post.Book.Image = bookImage; #endregion post.User = _userService.GetUserByUserName(User.Identity.Name); post.Labels = _labelService.GetLabelsById(postModel.LabelId); _postService.AddPost(post); _uow.SaveChanges(); #region Indexing new Post by Lucene.NET //Index the new Post lucene.NET new LucenePostSearch(_postService); Post lastPost = _postService.Find(post.Id); LucenePostSearch.AddUpdateLuceneIndex(new LucenePostModel { Labels = string.Join(" , ", lastPost.Labels.Select(l => l.Name).ToArray()), Body = HtmlUtility.RemoveHtmlTags(lastPost.Body), Description = lastPost.Description, Keywords = lastPost.Keyword, PostId = lastPost.Id, Title = lastPost.Title }); #endregion return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = "دانشنامه جدید با موقیت در سیستم ثبت شد", Mode = AlertMode.Success })); }
public virtual ActionResult EditUser(EditUserModel userModel) { ModelState.Remove("BirthDay"); if (!ModelState.IsValid) { return(PartialView(MVC.Admin.Shared.Views._ValidationSummery)); } var editedUser = new User { Email = userModel.Email, Id = userModel.Id, IsBaned = userModel.IsBaned, UserName = userModel.UserName, Role = _roleService.GetRoleByRoleId(userModel.RoleId), UserMetaData = new UserMetaData { BirthDay = userModel.BirthDay, Description = userModel.Description, FirstName = userModel.FirstName, LastName = userModel.LastName, Major = userModel.Major } }; if (!string.IsNullOrEmpty(userModel.Password)) { editedUser.Password = userModel.Password; editedUser.LastPasswordChange = DateAndTime.GetDateTime(); } if (userModel.IsBaned) { editedUser.BanedDate = DateAndTime.GetDateTime(); } EditedUserStatus editingStatus = _userService.EditUser(editedUser); string message; switch (editingStatus) { case EditedUserStatus.UpdatingUserSuccessfully: message = "اطلاعات کاربر با موفقیت به روز رسانی شد"; if (userModel.AvatarStatus == false) { AvatarImage.RemoveAvatarImage(userModel.UserName); } _uow.SaveChanges(); return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Message = message, Mode = AlertMode.Success })); // user added successfully case EditedUserStatus.EmailExist: message = "ایمیل وارد شده تکراری است"; break; case EditedUserStatus.UserNameExist: message = "نام کاربری تکراری است"; break; default: message = "نام کاربری یا ایمیل تکراری است"; break; } return(PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Mode = AlertMode.Error, Message = message })); }