public ActionResult DeleteConfirmed(int id)
        {
            ND_Category nD_Category = categoryManager.Find(x => x.Id == id);

            categoryManager.Delete(nD_Category);
            CacheHelper.RemoveCategoriesFromCache();

            return(RedirectToAction("Index"));
        }
        public ActionResult Create(ND_Category nD_Category)
        {
            ModelState.Remove("ModifiedUsername");

            if (ModelState.IsValid)
            {
                categoryManager.Insert(nD_Category);
                CacheHelper.RemoveCategoriesFromCache();

                return(RedirectToAction("Index"));
            }

            return(View(nD_Category));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ND_Category nD_Category = categoryManager.Find(x => x.Id == id.Value);

            if (nD_Category == null)
            {
                return(HttpNotFound());
            }
            return(View(nD_Category));
        }
        public ActionResult Edit(ND_Category nD_Category)
        {
            ModelState.Remove("ModifiedUsername");

            if (ModelState.IsValid)
            {
                ND_Category category = categoryManager.Find(x => x.Id == nD_Category.Id);
                category.Title       = nD_Category.Title;
                category.Description = nD_Category.Description;

                categoryManager.Update(category);
                CacheHelper.RemoveCategoriesFromCache();

                return(RedirectToAction("Index"));
            }
            return(View(nD_Category));
        }
Пример #5
0
        public ActionResult ByCategory(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }


            ND_Category cat = categoryManager.Find(x => x.Id == id.Value);

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


            return(View("Index", cat.Notes.OrderByDescending(x => x.ModifiedOn).ToList()));
        }
Пример #6
0
        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();
        }