コード例 #1
0
        public JsonResult RequestNewAd(int id)
        {
            var session = HttpContext.Session;

            if (session != null)
            {
                HttpContext.Session.TryGetValue("token", out var result);
                if (result != null)
                {
                    TempData["isLoggedIn"] = HttpContext.Session.GetString("token");
                    TempData["memberID"]   = HttpContext.Session.GetString("memberID");
                    int         memberID = Convert.ToInt32(TempData["memberID"].ToString());
                    Tbl_Ad      ad       = _AdService.Get(id);
                    Tbl_Request Request  = _RequestService.GetAll().Where(x => x.AdID == id && x.RequestMemberID == memberID).LastOrDefault();
                    if (Request == null && ad.MemberID != memberID)
                    {
                        Tbl_Request newRequest = new Tbl_Request()
                        {
                            AdID            = id,
                            RequestMemberID = memberID,
                            RequestStateID  = 1
                        };
                        _RequestService.Add(newRequest);
                    }
                    return(Json(Ok()));
                    // return Json("MemberRequestListCrud", "MemberPage");
                }
            }
            return(Json("Giriş Yapın"));
        }
コード例 #2
0
        public JsonResult RequestNewAdMessage(int id)
        {
            var session = HttpContext.Session;

            if (session != null)
            {
                HttpContext.Session.TryGetValue("token", out var result);
                if (result != null)
                {
                    TempData["isLoggedIn"] = HttpContext.Session.GetString("token");
                    TempData["memberID"]   = HttpContext.Session.GetString("memberID");
                    int         memberID    = Convert.ToInt32(TempData["memberID"].ToString());
                    Tbl_Ad      ad          = _AdService.Get(id);
                    Tbl_Request Request     = _RequestService.GetAll().Where(x => x.AdID == id && x.RequestMemberID == memberID).LastOrDefault();
                    Tbl_Message lastMessage = new Tbl_Message();
                    if (Request == null && ad.MemberID != memberID)
                    {
                        Tbl_Request newRequest = new Tbl_Request()
                        {
                            AdID            = id,
                            RequestMemberID = memberID,
                            RequestStateID  = 1
                        };
                        _RequestService.Add(newRequest);
                    }
                    Tbl_Request lastRequest = _RequestService.GetAll().LastOrDefault();
                    Tbl_Message message     = new Tbl_Message
                    {
                        SenderMemberID   = memberID,
                        Message          = "Konu Başlığı: " + ad.AdTitle,
                        MessageDate      = DateTime.Now,
                        MessageRequestID = lastRequest.RequestID,
                    };
                    _tbl_MessageService.Add(message);
                    lastMessage = _tbl_MessageService.GetAll().LastOrDefault();

                    return(Json(new { id = lastMessage.MessageID }));
                    //   return RedirectToAction("Message", "GeneralPage", new { id = lastMessage.MessageRequestID });
                }
            }
            return(Json("Giriş Yapınız"));
        }