コード例 #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
ファイル: BlogController.cs プロジェクト: bensaeed/mb.ir
        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!";
            }
        }