Beispiel #1
0
        public ActionResult InTheBag(int noteid, bool baged)
        {
            int res = 0;

            if (SessionManager.User == null)
            {
                return(Json(new { hasError = true, errorMessage = "Giriş yapmış kullanıcılar çantaya not atabilir!", result = 0 }));
            }

            UnBag bag =
                bagManager.Find(x => x.Note.Id == noteid && x.BagUser.Id == SessionManager.User.Id);

            UnNotes note = noteManager.Find(x => x.Id == noteid);

            if (bag != null && baged == false)
            {
                res = bagManager.Delete(bag);
            }
            else if (bag == null && baged == true)
            {
                res = bagManager.Insert(new UnBag()
                {
                    BagUser = SessionManager.User,
                    Note    = note
                });
            }

            if (res > 0)
            {
                if (baged)
                {
                    note.BagTotal++;
                }
                else
                {
                    note.BagTotal--;
                }

                res = noteManager.Update(note);

                return(Json(new { hasError = false, errorMessage = string.Empty, result = note.BagTotal }));
            }

            return(Json(new { hasError = true, errorMessage = "Çantaya not atma işlemi gerçekleştirilemedi.", result = note.BagTotal }));
        }