Пример #1
0
 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"));
 }
Пример #2
0
 public JsonResult GetCommentsDetails(int id)
 {
     using (var _Context = new ApplicationDbContext())
     {
         var _objEntityComment = new RepositoryPattern <PostComment>(_Context);
         var result            = _objEntityComment.GetByPredicate(x => x.ID == id);
         // _objEntityMedia.Dispose();
         return(Json(Data.UnProxy(_Context, result)));
     }
 }
Пример #3
0
 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();
             }
         }
     }
 }
Пример #4
0
 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"));
 }
Пример #5
0
 /// <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);
         }
     }
 }
Пример #6
0
        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"));
            }
        }
Пример #7
0
        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!";
            }
        }