public JsonResult EditComment(vmComment input) { if (!ModelState.IsValid) { return(Json("faild")); } try { using (var _Context = new ApplicationDbContext()) { var _objEntityComment = new RepositoryPattern <PostComment>(_Context); var CurrentItem = _objEntityComment.GetByPredicate(x => x.ID == input.ID); if (CurrentItem != null) { CurrentItem.Is_Active = input.Is_Active; CurrentItem.FullName = input.FullName; CurrentItem.Comment = input.Comment; _objEntityComment.Update(CurrentItem); _objEntityComment.Save(); _objEntityComment.Dispose(); } } } catch (Exception) { return(Json("OK")); } return(Json("OK")); }
public void SaveLog() { if (C_LikeViewList.CompareListCreateTimeWithTimeNow()) { var LstLikeView = C_LikeViewList.GetAllLikeView(); if (LstLikeView.Count() != 0) { using (var _Context = new ApplicationDbContext()) { var _objEntityActivity = new RepositoryPattern <Activity>(_Context); foreach (var item in LstLikeView) { if (item.ActionTypeID == Convert.ToInt32(EnumMethod.ActionType.View) || item.ActionTypeID == Convert.ToInt32(EnumMethod.ActionType.Like) || item.ActionTypeID == Convert.ToInt32(EnumMethod.ActionType.Downlaod)) { var NewItem = new Activity { ActionTime = item.ActionTime, DateMiladi = item.DateMiladi, DateShamsi = item.DateShamsi, ActivityTypeId = item.ActionTypeID, PostId = item.PostID, Browser = item.Browser, Device = item.Device, IP_Address = item.IP_Address, HostName = item.HostName, MoreInfo = "" }; _objEntityActivity.Insert(NewItem); } else if (item.ActionTypeID == Convert.ToInt32(EnumMethod.ActionType.DisLike)) { var CurrItemDele = _objEntityActivity.GetByPredicate(x => x.PostId == item.PostID && x.Browser == item.Browser && x.Device == item.Device && x.HostName == item.HostName && x.IP_Address == item.IP_Address && x.ActivityTypeId == Convert.ToInt32(EnumMethod.ActionType.Like)); if (CurrItemDele != null) { _objEntityActivity.Delete(CurrItemDele.ID); } } } _objEntityActivity.Save(); _objEntityActivity.Dispose(); C_LikeViewList.ClearLikeViewList(); } } } }
public async Task <ActionResult> Contact_US(string Name, string Phone, string Email, string Message, string CaptchaText) { if (CaptchaText.ToLower() == HttpContext.Session["captchastring"].ToString().ToLower()) { Session.Remove("captchastring"); var _objEntityMessage = new RepositoryPattern <Comment>(new ApplicationDbContext()); var NewItem = new Comment { FullName = Name, PhoneNumber = Phone, Email = Email, CommentUser = Message, SendDate = DateConvertor.DateToNumber(DateConvertor.TodayDate()), SendTime = DateConvertor.TimeNow(), Is_Read = "0" }; _objEntityMessage.Insert(NewItem); _objEntityMessage.Save(); _objEntityMessage.Dispose(); try { OpratingClasses.EmailService emailService = new OpratingClasses.EmailService(); var strSubject = " نام و نام خانوادگی : " + NewItem.FullName; var strMessage = " ارتباط با مديريت وب سايت" + " <br /> " + NewItem.CommentUser + " <br /> " + " ایمیل : " + NewItem.Email + " <br /> " + " شماره همراه : " + NewItem.PhoneNumber + " <br /> " + " تاریخ و ساعت ارسال : " + NewItem.SendDate + " - " + NewItem.SendTime; await emailService.SendMail(strSubject, strMessage); } catch (Exception) { } return(Json("OK")); } else { return(Json("CaptchaTextMistake")); //ViewBag.Message = "CAPTCHA verification failed!"; } }
public JsonResult ReadComment(int id) { try { using (var _Context = new ApplicationDbContext()) { var _objEntityComment = new RepositoryPattern <PostComment>(_Context); var CurrentItem = _objEntityComment.GetByPredicate(x => x.ID == id); if (CurrentItem != null) { CurrentItem.Is_Read = "1"; _objEntityComment.Update(CurrentItem); _objEntityComment.Save(); _objEntityComment.Dispose(); } } } catch (Exception) { return(Json("OK")); } return(Json("OK")); }
/// <summary> /// پاک کردن تصویر یک پست - وبلاگ /// </summary> /// <param name="PostID"></param> /// <returns></returns> public bool DeleteImageOfPost(string MediaID) { if (MediaID == null || MediaID == "") { return(false); } using (var _Context = new ApplicationDbContext()) { var _objEntityImage = new RepositoryPattern <Image>(_Context); var itemMedia = _objEntityImage.GetByPredicate(x => x.ID == MediaID); if (HelpOperation.RemoveMediaFromServer(itemMedia.FilePathOnServer)) { _objEntityImage.Delete(itemMedia.ID); _objEntityImage.Save(); _objEntityImage.Dispose(); return(true); } else { return(false); } } }
//public ContentResult UploadFile(HttpPostedFileBase hpf,List<vm_FileUploadInfo> vm_Info) public JsonResult PublishPost(vmPublishPost input) //string Title, int CategoryID, string Content, string IsActive, bool FlagHaveFile,string Tagsinput) { //, string Labels try { string NewImageID; //InfoUser AppUser = new InfoUser(); var TodayDateShamsi = DateConvertor.DateToNumber(DateConvertor.TodayDate()); //var NewNewsCode = HelpOperation.NewsCode(Convert.ToInt32(TodayDateShamsi)); if (input.FlagHaveFile == true) { HelpOperation.CreateArchiveFolderOnTheServer(); HttpPostedFileBase hpf = Request.Files[0] as HttpPostedFileBase; var FileSize = HelpOperation.ToFileSize(hpf.ContentLength); var GuidID = HelpOperation.NewGuidID(); var FileNameOnServer = GuidID + Path.GetExtension(hpf.FileName); var FilePath = @"~\MediaFiles\Image\" + FileNameOnServer; var FilePathOnServer = Server.MapPath(FilePath); var FileUrl = HelpOperation.MapToUrl(FilePath); Request.Files[0].SaveAs(FilePathOnServer); using (var _ContextImage = new ApplicationDbContext()) { var _objEntityImage = new RepositoryPattern <Image>(_ContextImage); var NewItemImage = new Image { ID = GuidID, TitleUrl = input.Title, FileName = FileNameOnServer, FileSize = FileSize, FileUrl = FileUrl, FilePathOnServer = FilePath }; NewImageID = GuidID; _objEntityImage.Insert(NewItemImage); _objEntityImage.Save(); _objEntityImage.Dispose(); } using (var _ContextPost = new ApplicationDbContext()) { var objEntityPost = new RepositoryPattern <Post>(_ContextPost); var newItemPost = new Post { Title = input.Title.Trim(), ImageID = NewImageID, CategoryID = input.CategoryID, //Categories = new List<Category>() { new Category() {ID = CategoryID, } }, Content = input.Content, IsActive = input.IsActive == "true" ? "0" : "1", Labels = input.Tagsinput.Trim(), SeoMetaDescription = input.SeoMetaDescription.Trim(), PostDate = DateConvertor.DateToNumber(DateConvertor.TodayDate()), PostTime = DateConvertor.TimeNowShort() }; objEntityPost.Insert(newItemPost); objEntityPost.Save(); objEntityPost.Dispose(); } } return(Json("OK")); } catch (Exception) { return(Json("Faild")); } }
public JsonResult EditPost(vmPublishPost input) { try { //delete image of Post To Insert New Image For Post (Update) if (input.FlagHaveFile == true) { DatabaseOperation objDatabaseOperation = new DatabaseOperation(); using (var _Context1 = new ApplicationDbContext()) { var objEntityPost = new RepositoryPattern <Post>(_Context1); var CurrentItem = objEntityPost.GetByPredicate(x => x.ID == input.PostID); if (objDatabaseOperation.DeleteImageOfPost(CurrentItem.ImageID)) { //InfoUser AppUser = new InfoUser(); var TodayDateShamsi = DateConvertor.DateToNumber(DateConvertor.TodayDate()); //var NewNewsCode = HelpOperation.NewsCode(Convert.ToInt32(TodayDateShamsi)); HelpOperation.CreateArchiveFolderOnTheServer(); HttpPostedFileBase hpf = Request.Files[0] as HttpPostedFileBase; var FileSize = HelpOperation.ToFileSize(hpf.ContentLength); var GuidID = CurrentItem.ImageID; var FileNameOnServer = GuidID + Path.GetExtension(hpf.FileName); var FilePath = @"~\MediaFiles\Image\" + FileNameOnServer; var FilePathOnServer = Server.MapPath(FilePath); var FileUrl = HelpOperation.MapToUrl(FilePath); Request.Files[0].SaveAs(FilePathOnServer); using (var _ContextImage = new ApplicationDbContext()) { var _objEntityImage = new RepositoryPattern <Image>(_ContextImage); var NewItemImage = new Image { ID = GuidID, TitleUrl = input.Title, FileName = FileNameOnServer, FileSize = FileSize, FileUrl = FileUrl, FilePathOnServer = FilePath }; _objEntityImage.Insert(NewItemImage); _objEntityImage.Save(); _objEntityImage.Dispose(); } } } } using (var _context = new ApplicationDbContext()) { var objEntityPost = new RepositoryPattern <Post>(_context); var CurrentItem = objEntityPost.GetByPredicate(x => x.ID == input.PostID); CurrentItem.Title = input.Title.Trim(); CurrentItem.CategoryID = input.CategoryID; //Categories = new List<Category>() { new Category() {ID = CategoryID, } }, CurrentItem.Content = input.Content; CurrentItem.IsActive = input.IsActive == "true" ? "0" : "1"; CurrentItem.Labels = input.Tagsinput.Trim(); CurrentItem.SeoMetaDescription = input.SeoMetaDescription.Trim(); //CurrentItem.PostDate = DateConvertor.DateToNumber(DateConvertor.TodayDate()); //CurrentItem.PostTime = DateConvertor.TimeNowShort(); objEntityPost.Update(CurrentItem); objEntityPost.Save(); objEntityPost.Dispose(); } return(Json("OK")); } catch (Exception) { return(Json("Faild")); } }
public IEnumerable <vm_AllPost> GetAllPost(string PostCount) { using (var _Context = new ApplicationDbContext()) { var _objEntityPost = new RepositoryPattern <Post>(_Context); var _post = _objEntityPost.GetAll(); //var _post = _objEntityPost.SearchFor(x => x.IsActive == "1").ToList(); var _objEntityCategory = new RepositoryPattern <Category>(_Context); var _category = _objEntityCategory.GetAll(); var _objEntityImage = new RepositoryPattern <Image>(_Context); var _image = _objEntityImage.GetAll(); var Result = new List <vm_AllPost>(); Result = (from pst in _post join im in _image on pst.ImageID equals im.ID join cat in _category on pst.CategoryID equals cat.ID //join ac in _activity //on pst.ID equals ac.Posts.ID into act //from PstAc in act.DefaultIfEmpty() select new vm_AllPost { PostID = pst.ID, Content = pst.Content, SeoMetaDescription = pst.SeoMetaDescription, LikeCount = pst.Activity.Where(x => x.ActivityTypeId == 2).Count(), //totalCount(ac.Posts.ID), Category = cat.DescriptionFa, Labels = pst.Labels, PostDate = pst.PostDate, PostTime = pst.PostTime, Title = pst.Title, ViewCount = pst.Activity.Where(x => x.ActivityTypeId == 1).Count(), ImageUrl = im.FileUrl.Substring(1), //_image.Single(x=>x.ID==pst.ImageID).FileUrl, //pst.Image.FileUrl, IsActive = pst.IsActive, CategoryID = pst.CategoryID } ).OrderByDescending(x => x.PostTime) .ThenByDescending(x => x.PostDate) .ToList(); _objEntityPost.Dispose(); _objEntityCategory.Dispose(); _objEntityImage.Dispose(); if (PostCount == "all") { return(Result); } else if (Convert.ToInt32(PostCount) > 0) { return(Result.Where(x => x.IsActive == "1").Take(Convert.ToInt32(PostCount))); } else { return(Result); } } }
public void StartOperation(string CurrentClientIP) { NetworkOperation objNetworkOperation = new NetworkOperation(); //string CurrentClientIP = ClientIPaddress(); IpInformation IpInfo = GetLocationIPINFO(CurrentClientIP); var _objEntityWebsiteVisit = new RepositoryPattern <WebsiteVisit>(new ApplicationDbContext()); var newItem = new WebsiteVisit { VisitTime = TimeNow(), DateShamsi = DateConvertor.DateToNumber(DateConvertor.TodayDate()), DateMiladi = DateConvertor.DateToNumber(DateConvertor.TodayDateMiladi()), Browser = objNetworkOperation.ClientBrowser(), DeviceInfo = objNetworkOperation.ClientDeviceType(), IP_Address = CurrentClientIP, HostName = objNetworkOperation.ClientHostName(), country = IpInfo.country, //asn = IpInfo.@as, city = IpInfo.city, countryCode = IpInfo.countryCode, isp = IpInfo.isp, lat = IpInfo.lat, lon = (IpInfo.lon), org = IpInfo.org, query = IpInfo.query, region = IpInfo.region, regionName = IpInfo.regionName, status = IpInfo.status, timezone = IpInfo.timezone, zip = IpInfo.zip, district = IpInfo.district, mobile = IpInfo.mobile, // == true? "1" : "0", proxy = IpInfo.proxy, // == true ? "1" : "0" reverse = IpInfo.reverse }; _objEntityWebsiteVisit.Insert(newItem); _objEntityWebsiteVisit.Save(); try { var strSubject = " بازديد از وبسايت " + newItem.DateShamsi + " " + newItem.VisitTime; var strMessage = " بازديد وب سايت" + " <br /> " + " IP Address : " + newItem.IP_Address + " <br /> " + " مشخصات دستگاه : " + newItem.DeviceInfo + " <br /> " + " كشور : " + newItem.country + " <br /> " + " شهر و منطقه : " + newItem.regionName + " - " + newItem.city; OpratingClasses.EmailService emailService = new OpratingClasses.EmailService(); Task.Factory.StartNew(() => emailService.SendMail(strSubject, strMessage)); } catch (Exception) { } var cou = newItem.ID; _objEntityWebsiteVisit.Dispose(); }
public async Task <ActionResult> AddComment(vmComment input) { if (!ModelState.IsValid) { foreach (var item in ModelState) { var errors = item.Value.Errors.ToList(); } return(Json("null")); } if (input.CaptchaText.ToLower() == HttpContext.Session["captchastring"].ToString().ToLower()) { Session.Remove("captchastring"); NetworkOperation objNetworkOperation = new NetworkOperation(); VisitWebsiteLog visitWebsiteLog = new VisitWebsiteLog(); string CurrentClientIP = null; CurrentClientIP = objNetworkOperation.ClientIPaddress(); IpInformation IpInfo = visitWebsiteLog.GetLocationIPINFO(CurrentClientIP); var _objEntityMessage = new RepositoryPattern <PostComment>(new ApplicationDbContext()); var NewItem = new PostComment { PostID = input.PostID, FullName = input.FullName, Comment = input.Comment, Email = input.Email, SendDate = DateConvertor.DateToNumber(DateConvertor.TodayDate()), SendTime = DateConvertor.TimeNow(), Browser = objNetworkOperation.ClientBrowser(), DeviceInfo = objNetworkOperation.ClientDeviceType(), IP_Address = CurrentClientIP, HostName = objNetworkOperation.ClientHostName(), country = IpInfo.country, city = IpInfo.city, countryCode = IpInfo.countryCode, org = IpInfo.org, region = IpInfo.region, regionName = IpInfo.regionName, status = IpInfo.status, timezone = IpInfo.timezone, mobile = IpInfo.mobile == true ? true :false, Is_Active = "1" }; _objEntityMessage.Insert(NewItem); _objEntityMessage.Save(); _objEntityMessage.Dispose(); try { var _objEntityPost = new RepositoryPattern <Post>(new ApplicationDbContext()); OpratingClasses.EmailService emailService = new OpratingClasses.EmailService(); var strSubject = " نام و نام خانوادگی : " + NewItem.FullName; var strMessage = " ديدگاه كاربر راجع به پست : " + _objEntityPost.GetByPredicate(X => X.ID == NewItem.PostID).Title.Trim() + " <br /> " + NewItem.Comment + " <br /> " + " ایمیل : " + NewItem.Email + " <br /> " + " ساير اطلاعات : " + NewItem.DeviceInfo + " - " + NewItem.country + NewItem.city + " <br /> " + " تاریخ و ساعت ارسال : " + NewItem.SendDate + " - " + NewItem.SendTime; //" <br /> <p styel=\"font-family:\"Tahoma;\"\">" + NewItem.Comment + await emailService.SendMail(strSubject, strMessage); } catch (Exception) { } return(PartialView("_PartialPageComment", NewItem)); } else { return(Json("CaptchaTextMistake")); //ViewBag.Message = "CAPTCHA verification failed!"; } }