コード例 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            WebnoteUser WebnoteUser = WebnoteUserManager.Find(x => x.Id == id);

            WebnoteUserManager.Delete(WebnoteUser);

            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public string GetCurrentUsername()
        {
            if (HttpContext.Current.Session["login"] != null)
            {
                WebnoteUser user = HttpContext.Current.Session["login"] as WebnoteUser;
                return(user.Username);
            }

            return("system");
        }
コード例 #3
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            WebnoteUser WebnoteUser = WebnoteUserManager.Find(x => x.Id == id.Value);

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

            return(View(WebnoteUser));
        }
コード例 #4
0
        public ActionResult Edit(WebnoteUser WebnoteUser)
        {
            ModelState.Remove("CreatedOn");
            ModelState.Remove("ModifiedOn");
            ModelState.Remove("ModifiedUsername");

            if (ModelState.IsValid)
            {
                BusinessLayerResult <WebnoteUser> res = WebnoteUserManager.Update(WebnoteUser);

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

                return(RedirectToAction("Index"));
            }
            return(View(WebnoteUser));
        }
コード例 #5
0
        public ActionResult EditProfile(WebnoteUser model, HttpPostedFileBase ProfileImage)
        {
            ModelState.Remove("ModifiedUsername");

            if (ModelState.IsValid)
            {
                if (ProfileImage != null &&
                    (ProfileImage.ContentType == "image/jpeg" ||
                     ProfileImage.ContentType == "image/jpg" ||
                     ProfileImage.ContentType == "image/png"))
                {
                    string filename = $"user_{model.Id}.{ProfileImage.ContentType.Split('/')[1]}";

                    ProfileImage.SaveAs(Server.MapPath($"~/images/{filename}"));
                    model.ProfileImageFilename = filename;
                }

                BusinessLayerResult <WebnoteUser> res = webnoteUserManager.UpdateProfile(model);

                if (res.Errors.Count > 0)
                {
                    ErrorViewModel errorNotifyObj = new ErrorViewModel()
                    {
                        Items          = res.Errors,
                        Title          = "Profil Güncellenemedi.",
                        RedirectingUrl = "/Home/EditProfile"
                    };

                    return(View("Error", errorNotifyObj));
                }

                // Profil güncellendiği için session güncellendi.
                CurrentSession.Set <WebnoteUser>("login", res.Result);

                return(RedirectToAction("ShowProfile"));
            }

            return(View(model));
        }
コード例 #6
0
        protected override void Seed(DatabaseContext context)
        {
            // Adding admin user..
            WebnoteUser admin = new WebnoteUser()
            {
                Name                 = "Salih",
                Surname              = "Şeker",
                Email                = "*****@*****.**",
                ActivateGuid         = Guid.NewGuid(),
                IsActive             = true,
                IsAdmin              = true,
                Username             = "******",
                ProfileImageFilename = "user_boy.png",
                Password             = "******",
                CreatedOn            = DateTime.Now,
                ModifiedOn           = DateTime.Now.AddMinutes(5),
                ModifiedUsername     = "******"
            };

            // Adding standart user..
            WebnoteUser standartUser = new WebnoteUser()
            {
                Name                 = "Suleyman",
                Surname              = "Şeker",
                Email                = "*****@*****.**",
                ActivateGuid         = Guid.NewGuid(),
                IsActive             = true,
                IsAdmin              = false,
                Username             = "******",
                Password             = "******",
                ProfileImageFilename = "user_boy.png",
                CreatedOn            = DateTime.Now.AddHours(1),
                ModifiedOn           = DateTime.Now.AddMinutes(65),
                ModifiedUsername     = "******"
            };

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

            for (int i = 0; i < 8; i++)
            {
                WebnoteUser user = new WebnoteUser()
                {
                    Name    = FakeData.NameData.GetFirstName(),
                    Surname = FakeData.NameData.GetSurname(),
                    Email   = FakeData.NetworkData.GetEmail(),
                    ProfileImageFilename = "user_boy.png",
                    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.WebnoteUsers.Add(user);
            }

            context.SaveChanges();

            // User list for using..
            List <WebnoteUser> userlist = context.WebnoteUsers.ToList();

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

                context.Categories.Add(cat);
                cat.Notes = new List <Note>();

                // Adding fake notes..
                for (int k = 0; k < FakeData.NumberData.GetNumber(5, 9); k++)
                {
                    WebnoteUser owner = userlist[FakeData.NumberData.GetNumber(0, userlist.Count - 1)];

                    Note note = new Note()
                    {
                        Title            = FakeData.TextData.GetAlphabetical(FakeData.NumberData.GetNumber(5, 25)),
                        Text             = FakeData.TextData.GetSentences(FakeData.NumberData.GetNumber(1, 3)),
                        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,
                    };

                    note.Comments = new List <Comment>();
                    note.Likes    = new List <Liked>();

                    // Adding fake comments
                    for (int j = 0; j < FakeData.NumberData.GetNumber(3, 5); j++)
                    {
                        WebnoteUser comment_owner = userlist[FakeData.NumberData.GetNumber(0, userlist.Count - 1)];

                        Comment comment = new Comment()
                        {
                            Text             = FakeData.TextData.GetSentence(),
                            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);
                    }

                    // Adding fake likes..

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

                        note.Likes.Add(liked);
                    }

                    cat.Notes.Add(note);
                }
            }

            context.SaveChanges();
        }