public ActionResult DeleteConfirmed(int id)
        {
            ND_Note nD_Note = noteManager.Find(x => x.Id == id);

            noteManager.Delete(nD_Note);
            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public ActionResult Create(ND_Comment comment, int?noteid)
        {
            ModelState.Remove("CreatedOn");
            ModelState.Remove("ModifiedOn");
            ModelState.Remove("ModifiedUsername");

            if (ModelState.IsValid)
            {
                if (noteid == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

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

                if (note == null)
                {
                    return(HttpNotFound());
                }

                comment.Note  = note;
                comment.Owner = CurrentSession.User;

                if (commentManager.Insert(comment) > 0)
                {
                    return(Json(new { result = true }, JsonRequestBehavior.AllowGet));
                }
            }

            return(Json(new { result = false }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ND_Note nD_Note = noteManager.Find(x => x.Id == id.Value);

            if (nD_Note == null)
            {
                return(HttpNotFound());
            }
            return(View(nD_Note));
        }
        public ActionResult Create(ND_Note nD_Note)
        {
            ModelState.Remove("ModifiedUsername");

            if (ModelState.IsValid)
            {
                nD_Note.Owner = CurrentSession.User;
                noteManager.Insert(nD_Note);
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(CacheHelper.GetCategoriesFromCache(), "Id", "Title", nD_Note.CategoryId);
            return(View(nD_Note));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ND_Note nD_Note = noteManager.Find(x => x.Id == id.Value);

            if (nD_Note == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CategoryId = new SelectList(CacheHelper.GetCategoriesFromCache(), "Id", "Title", nD_Note.CategoryId);
            return(View(nD_Note));
        }
Exemple #6
0
        // GET: Comment
        public ActionResult ShowNoteComments(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ND_Note note = noteManager.ListQueryable().Include("Comments").FirstOrDefault(x => x.Id == id.Value);

            if (note == null)
            {
                return(HttpNotFound());
            }
            return(PartialView("_CommentsPartial", note.Comments));
        }
        public ActionResult GetNoteText(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ND_Note note = noteManager.Find(x => x.Id == id);

            if (note == null)
            {
                return(HttpNotFound());
            }

            return(PartialView("_NotesPartial", note));
        }
        public ActionResult Edit(ND_Note nD_Note)
        {
            ModelState.Remove("ModifiedUsername");

            if (ModelState.IsValid)
            {
                ND_Note note = noteManager.Find(x => x.Id == nD_Note.Id);
                note.Text       = nD_Note.Text;
                note.Title      = nD_Note.Title;
                note.IsDraft    = nD_Note.IsDraft;
                note.CategoryId = nD_Note.CategoryId;

                noteManager.Update(note);

                return(RedirectToAction("Index"));
            }
            ViewBag.CategoryId = new SelectList(CacheHelper.GetCategoriesFromCache(), "Id", "Title", nD_Note.CategoryId);
            return(View(nD_Note));
        }
        public ActionResult SetLikeState(int noteid, bool liked)
        {
            int res = 0;

            ND_Liked like = likedManager.Find(x => x.Note.Id == noteid && x.LikedUser.Id == CurrentSession.User.Id);
            ND_Note  note = noteManager.Find(x => x.Id == noteid);

            if (like != null && liked == false)
            {
                res = likedManager.Delete(like);
            }
            else if (like == null && liked == true)
            {
                res = likedManager.Insert(new ND_Liked()
                {
                    LikedUser = CurrentSession.User,
                    Note      = note
                });
            }

            if (res > 0)
            {
                if (liked)
                {
                    note.LikeCount++;
                }
                else
                {
                    note.LikeCount--;
                }

                res = noteManager.Update(note);

                return(Json(new { hasError = false, errorMessage = "", result = note.LikeCount }));
            }


            return(Json(new { hasError = true, errorMessage = "Beğenme işlemi hatalı.", result = note.LikeCount }));
        }
        protected override void Seed(DatabaseContext context)
        {
            ND_User admin = new ND_User()
            {
                Name                 = "Erhan",
                Surname              = "Külekci",
                Username             = "******",
                Email                = "*****@*****.**",
                ActivatedGuid        = Guid.NewGuid(),
                ProfileImageFilename = "user-default.png",
                IsActive             = true,
                IsAdmin              = true,
                Password             = "******",
                CreatedOn            = DateTime.Now,
                ModifiedOn           = DateTime.Now.AddMinutes(5),
                ModifiedUserName     = "******"
            };

            ND_User standartUser = new ND_User()
            {
                Name                 = "Orhan",
                Surname              = "Külekci",
                Username             = "******",
                Email                = "*****@*****.**",
                ActivatedGuid        = Guid.NewGuid(),
                ProfileImageFilename = "user-default.png",
                IsActive             = true,
                IsAdmin              = false,
                Password             = "******",
                CreatedOn            = DateTime.Now.AddHours(1),
                ModifiedOn           = DateTime.Now.AddMinutes(5),
                ModifiedUserName     = "******"
            };

            context.Users.Add(admin);
            context.Users.Add(standartUser);

            //addin for user...
            for (int i = 0; i < 8; i++)
            {
                ND_User User = new ND_User()
                {
                    Name                 = FakeData.NameData.GetFirstName(),
                    Surname              = FakeData.NameData.GetSurname(),
                    Username             = $"user{i}",
                    Email                = FakeData.NetworkData.GetEmail(),
                    ActivatedGuid        = Guid.NewGuid(),
                    ProfileImageFilename = "user-default.png",
                    IsActive             = true,
                    IsAdmin              = false,
                    Password             = "******",
                    CreatedOn            = FakeData.DateTimeData.GetDatetime(),
                    ModifiedOn           = FakeData.DateTimeData.GetDatetime(),
                    ModifiedUserName     = $"user{i}"
                };

                context.Users.Add(User);
            }

            context.SaveChanges();

            List <ND_User> userList = context.Users.ToList();

            //Adding for fake categories..
            for (int i = 0; i < 10; i++)
            {
                ND_Category category = new ND_Category()
                {
                    Title            = FakeData.PlaceData.GetStreetName(),
                    Description      = FakeData.PlaceData.GetAddress(),
                    CreatedOn        = DateTime.Now,
                    ModifiedOn       = DateTime.Now,
                    ModifiedUserName = "******"
                };

                context.Categories.Add(category);

                //adding for note..
                for (int j = 0; j < FakeData.NumberData.GetNumber(5, 10); j++)
                {
                    ND_User owner = userList[FakeData.NumberData.GetNumber(0, userList.Count - 1)];

                    ND_Note note = new ND_Note()
                    {
                        Title            = FakeData.TextData.GetAlphabetical(FakeData.NumberData.GetNumber(5, 25)),
                        Text             = FakeData.TextData.GetSentences(FakeData.NumberData.GetNumber(5, 25)),
                        IsDraft          = false,
                        LikeCount        = FakeData.NumberData.GetNumber(1, 9),
                        Owner            = owner,
                        CreatedOn        = FakeData.DateTimeData.GetDatetime(),
                        ModifiedOn       = FakeData.DateTimeData.GetDatetime(),
                        ModifiedUserName = owner.Username
                    };

                    category.Notes.Add(note);

                    //adding for comments
                    for (int k = 0; k < FakeData.NumberData.GetNumber(2, 8); k++)
                    {
                        ND_User owner_comment = userList[FakeData.NumberData.GetNumber(0, userList.Count - 1)];

                        ND_Comment comment = new ND_Comment()
                        {
                            Text             = FakeData.TextData.GetSentence(),
                            Owner            = owner_comment,
                            CreatedOn        = FakeData.DateTimeData.GetDatetime(),
                            ModifiedOn       = FakeData.DateTimeData.GetDatetime(),
                            ModifiedUserName = owner_comment.Username
                        };

                        note.Comments.Add(comment);
                    }

                    //adding for likes

                    for (int e = 0; e < note.LikeCount; e++)
                    {
                        ND_Liked liked = new ND_Liked()
                        {
                            LikedUser = userList[e]
                        };

                        note.Likes.Add(liked);
                    }
                }
            }

            context.SaveChanges();
        }