Beispiel #1
0
        public ActionResult EditProfile()
        {
            BooknoteUser currentUser = Session["login"] as BooknoteUser;
            BusinessLayerResult <BooknoteUser> res = um.GetUserById(currentUser.Id);

            return(View(res.Result));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            BooknoteUser booknoteUser = bum.Find(x => x.Id == id);

            bum.Delete(booknoteUser);

            return(RedirectToAction("Index"));
        }
Beispiel #3
0
 public string GetCurrentUserName()
 {
     if (HttpContext.Current.Session["login"] != null)
     {
         BooknoteUser user = HttpContext.Current.Session["login"] as BooknoteUser;
         return(user.Username);
     }
     return("system");
 }
Beispiel #4
0
        public ActionResult DeleteProfile()
        {
            BooknoteUser currentUser = Session["login"] as BooknoteUser;
            BusinessLayerResult <BooknoteUser> res = um.RemoveUserById(currentUser.Id);

            Session.Clear();

            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BooknoteUser booknoteUser = bum.Find(x => x.Id == id.Value);

            if (booknoteUser == null)
            {
                return(HttpNotFound());
            }
            return(View(booknoteUser));
        }
Beispiel #6
0
        public ActionResult EditProfile(BooknoteUser model)
        {
            BusinessLayerResult <BooknoteUser> res = um.UpdateProfile(model);

            if (ModelState.IsValid)
            {
                if (res.Errors.Count > 0)
                {
                    res.Errors.ForEach(x => ModelState.AddModelError("", x));
                    return(View(model));
                }

                Session["login"] = res.Result;
                return(RedirectToAction("ShowProfile"));
            }

            return(View(model));
        }
        public ActionResult Edit(BooknoteUser booknoteUser)
        {
            ModelState.Remove("CreatedOn");
            ModelState.Remove("ModifiedOn");
            ModelState.Remove("ModifiedUsername");

            if (ModelState.IsValid)
            {
                BusinessLayerResult <BooknoteUser> res = bum.Update(booknoteUser);

                if (res.Errors.Count > 0)
                {
                    res.Errors.ForEach(x => ModelState.AddModelError("", x));
                    return(View(booknoteUser));
                }

                return(RedirectToAction("Index"));
            }
            return(View(booknoteUser));
        }
Beispiel #8
0
        protected override void Seed(DatabaseContext context)
        {
            BooknoteUser admin = new BooknoteUser()
            {
                Name             = "Serdar",
                Surname          = "Filik",
                Email            = "*****@*****.**",
                ActivateGuid     = Guid.NewGuid(),
                IsActive         = true,
                IsAdmin          = true,
                Username         = "******",
                Password         = "******",
                CreatedOn        = DateTime.Now,
                ModifiedOn       = DateTime.Now.AddMinutes(5),
                ModifiedUsername = "******"
            };

            BooknoteUser standartUser = new BooknoteUser()
            {
                Name             = "Katya",
                Surname          = "Filik",
                Email            = "*****@*****.**",
                ActivateGuid     = Guid.NewGuid(),
                IsActive         = true,
                IsAdmin          = false,
                Username         = "******",
                Password         = "******",
                CreatedOn        = DateTime.Now.AddHours(1),
                ModifiedOn       = DateTime.Now.AddMinutes(65),
                ModifiedUsername = "******"
            };

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

            for (int i = 0; i < 8; i++)
            {
                BooknoteUser user = new BooknoteUser()
                {
                    Name             = FakeData.NameData.GetFirstName(),
                    Surname          = FakeData.NameData.GetSurname(),
                    Email            = FakeData.NetworkData.GetEmail(),
                    ActivateGuid     = Guid.NewGuid(),
                    IsActive         = true,
                    IsAdmin          = false,
                    Username         = $"user{i}",
                    Password         = "******",
                    CreatedOn        = FakeData.DateTimeData.GetDatetime(DateTime.Now.AddYears(-1), DateTime.Now),
                    ModifiedOn       = FakeData.DateTimeData.GetDatetime(DateTime.Now.AddYears(-1), DateTime.Now),
                    ModifiedUsername = $"user{i}"
                };

                context.BookNoteUsers.Add(user);
            }

            context.SaveChanges();

            List <BooknoteUser> userList = context.BookNoteUsers.ToList();

            //Fake data ekleme
            for (int i = 0; i < 10; i++)
            {
                //kategori ekleme
                Category cat = new Category()
                {
                    Title            = FakeData.NameData.GetFemaleFirstName(),
                    Description      = FakeData.PlaceData.GetAddress(),
                    CreatedOn        = DateTime.Now,
                    ModifiedOn       = DateTime.Now,
                    ModifiedUsername = "******"
                };
                context.Categories.Add(cat);

                for (int j = 0; j < FakeData.NumberData.GetNumber(5, 9); j++)
                {
                    BooknoteUser owner = userList[FakeData.NumberData.GetNumber(0, userList.Count - 1)];
                    //note ekleme
                    Note note = new Note()
                    {
                        Title            = FakeData.TextData.GetAlphabetical(FakeData.NumberData.GetNumber(5, 25)),
                        Text             = FakeData.TextData.GetSentences(FakeData.NumberData.GetNumber(1, 3)),
                        Category         = cat,
                        IsDraft          = false,
                        LikeCount        = FakeData.NumberData.GetNumber(1, 9),
                        Owner            = owner,
                        CreatedOn        = FakeData.DateTimeData.GetDatetime(DateTime.Now.AddYears(-1), DateTime.Now),
                        ModifiedOn       = FakeData.DateTimeData.GetDatetime(DateTime.Now.AddYears(-1), DateTime.Now),
                        ModifiedUsername = owner.Username,
                    };
                    cat.Notes.Add(note);

                    //comment ekleme
                    for (int k = 0; k < FakeData.NumberData.GetNumber(3, 5); k++)
                    {
                        BooknoteUser comment_owner = userList[FakeData.NumberData.GetNumber(0, userList.Count - 1)];
                        Comment      comment       = new Comment()
                        {
                            Text             = FakeData.TextData.GetSentence(),
                            Note             = note,
                            Owner            = comment_owner,
                            CreatedOn        = FakeData.DateTimeData.GetDatetime(DateTime.Now.AddYears(-1), DateTime.Now),
                            ModifiedOn       = FakeData.DateTimeData.GetDatetime(DateTime.Now.AddYears(-1), DateTime.Now),
                            ModifiedUsername = comment_owner.Username,
                        };

                        note.Comments.Add(comment);
                    }

                    //like ekleme


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

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

            context.SaveChanges();
        }