示例#1
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));
        }
示例#2
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ND_Comment comment = commentManager.Find(x => x.Id == id.Value);

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

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

            return(Json(new { result = false }, JsonRequestBehavior.AllowGet));
        }
示例#3
0
        public ActionResult Edit(int?id, string text)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ND_Comment comment = commentManager.Find(x => x.Id == id.Value);

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

            comment.Text = text;

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

            return(Json(new { result = false }, JsonRequestBehavior.AllowGet));
        }
        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();
        }