コード例 #1
0
        public ActionResult Delete(int picId)
        {
            using (ProjektEntities context = new ProjektEntities())
            {
                var picture  = context.Pictures.Where(a => a.id == picId).FirstOrDefault();
                var pical    = context.PicturesAlbums.Where(a => a.pictures_id == picId).ToList();
                var comments = context.Comments.Where(a => a.id_picture == picId).ToList();

                foreach (Comments comment in comments)
                {
                    context.Comments.Remove(comment);
                }
                foreach (PicturesAlbums p in pical)
                {
                    context.PicturesAlbums.Remove(p);
                }
                context.Pictures.Remove(picture);
                context.SaveChanges();
            }
            HomeModel homeModel = new HomeModel();

            IndexView(homeModel);
            ViewBag.Deleted = "true";
            ViewBag.msg     = "Zdjęcie zostało usunięte";
            return(RedirectToAction("Index", "Home"));
        }
コード例 #2
0
ファイル: AlbumController.cs プロジェクト: Filcz9/DNetProject
        public HomeModel Pictures(HomeModel homeModel, int albumId)
        {
            List <Pictures> pictureList = new List <Pictures>();

            using (ProjektEntities context = new ProjektEntities())
            {
                var pictures =
                    from p in context.Pictures
                    from c in context.PicturesAlbums
                    where p.id == c.pictures_id && albumId == c.album_id
                    select p;

                foreach (var picture in pictures)
                {
                    pictureList.Add(picture);
                }

                pictureList.Reverse();
                homeModel.pictureList = pictureList;



                return(homeModel);
            }
        }
コード例 #3
0
        // GET: Znajomi
        public ActionResult Index()
        {
            ProjektEntities db     = new ProjektEntities();
            var             friend = from i in db.FRIENDS
                                     where i.User_ID == User.Identity.Name
                                     join us in db.USER
                                     on i.Friend_ID equals us.User_ID
                                     where us.Is_Exists == true
                                     select new { us.User_ID, us.Image };

            var mod = new FriendsListView
            {
                ListFriends = new List <FriendsView>(),
                ListSearch  = new List <FriendsView>()
            };

            foreach (var x in friend)
            {
                mod.ListFriends.Add(new FriendsView {
                    UserID = x.User_ID, imageData = x.Image
                });
            }

            return(View(mod));
        }
コード例 #4
0
        public ActionResult ForgotPassword(string Email)
        {
            //Verify Email ID
            //Generate Reset password link
            //Send Email
            string message = "";
            bool   status  = false;

            using (ProjektEntities dc = new ProjektEntities())
            {
                var account = dc.Users.Where(a => a.email == Email).FirstOrDefault();
                if (account != null)
                {
                    //Send email for reset password
                    string resetCode = Guid.NewGuid().ToString();
                    SendVerificationLinkEmail(account.email, resetCode, "ResetPassword");
                    account.ResetPasswordCode = resetCode;
                    //This line I have added here to avoid confirm password not match issue , as we had added a confirm password property
                    //in our model class in part 1
                    dc.Configuration.ValidateOnSaveEnabled = false;
                    dc.SaveChanges();
                    message = "Reset password link has been sent to your email";
                }
                else
                {
                    message = "Account not found";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
コード例 #5
0
ファイル: UserManager.cs プロジェクト: damifil/WWW_MVC_BET
 public bool IsLoginExist(string login)    // sprawdzenie czy login istnieje w bazie danych
 {
     using (ProjektEntities db = new ProjektEntities())
     {
         return(db.USER.Where(u => u.User_ID.Equals(login)).Any());
     }
 }
コード例 #6
0
        public ActionResult Comment(Comments Comment, int id)
        {
            HomeModel       homeModel       = new HomeModel();
            List <Comments> pictureComments = new List <Comments>();
            var             currentUserId   = UserId(User.Identity.Name);

            using (ProjektEntities context = new ProjektEntities())
            {
                Comments Comment2 = new Comments
                {
                    text       = Comment.text,
                    id_user    = currentUserId,
                    id_picture = id
                };
                context.Comments.Add(Comment2);
                context.SaveChanges();

                var comments =
                    from c in context.Comments
                    join u in context.Users on c.id_user equals u.id into ps
                    where c.id_picture == id
                    select new { Comment = c, Users = ps };

                foreach (var comment in comments)
                {
                    pictureComments.Add(comment.Comment);
                }
                homeModel.pictureComments = pictureComments;
            }

            return(PartialView("Comment", homeModel));
        }
コード例 #7
0
ファイル: UserManager.cs プロジェクト: damifil/WWW_MVC_BET
 public bool IsUserExists(string login)
 {
     using (ProjektEntities db = new ProjektEntities())
     {
         return(db.USER.Where(u => u.User_ID.Equals(login)).Where(u => u.Is_Exists == true).Any());
     }
 }
コード例 #8
0
        public ActionResult AddToPrivate(Albums album, int id)
        {
            HomeModel       homeModel       = new HomeModel();
            List <Comments> pictureComments = new List <Comments>();
            var             currentUserId   = UserId(User.Identity.Name);

            using (ProjektEntities context = new ProjektEntities())
            {
                PicturesAlbums picturesAlbums = new PicturesAlbums
                {
                    pictures_id = id,
                    album_id    = album.id
                };

                context.PicturesAlbums.Add(picturesAlbums);
                context.SaveChanges();

                var comments =
                    from c in context.Comments
                    join u in context.Users on c.id_user equals u.id into ps
                    where c.id_picture == id
                    select new { Comment = c, Users = ps };

                foreach (var comment in comments)
                {
                    pictureComments.Add(comment.Comment);
                }
                homeModel.pictureComments = pictureComments;
            }

            return(PartialView("Comment", homeModel));
        }
コード例 #9
0
        public ActionResult ResetPassword(string id)
        {
            //Verify the reset password link
            //Find account associated with this link
            //redirect to reset password page
            if (string.IsNullOrWhiteSpace(id))
            {
                return(HttpNotFound());
            }

            using (ProjektEntities dc = new ProjektEntities())
            {
                var user = dc.Users.Where(a => a.ResetPasswordCode == id).FirstOrDefault();
                if (user != null)
                {
                    ResetPasswordModel model = new ResetPasswordModel();
                    model.ResetCode = id;
                    return(View(model));
                }
                else
                {
                    return(HttpNotFound());
                }
            }
        }
コード例 #10
0
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (ProjektEntities dc = new ProjektEntities())
                {
                    var user = dc.Users.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault();
                    if (user != null)
                    {
                        user.password          = Crypto.Hash(model.NewPassword);
                        user.ResetPasswordCode = "";
                        dc.Configuration.ValidateOnSaveEnabled = false;
                        dc.SaveChanges();
                        message = "New password updated successfully";
                    }
                }
            }
            else
            {
                message = "Something is invalid";
            }
            ViewBag.Message = message;
            return(View(model));
        }
コード例 #11
0
        public ActionResult DeleteUser(string username)
        {
            List <Users> userList = new List <Users>();

            using (ProjektEntities context = new ProjektEntities())
            {
                var user    = context.Users.Where(a => a.username == username).FirstOrDefault();
                var comment = context.Comments.Where(a => a.id_user == user.id).ToList();
                context.Users.Remove(user);


                foreach (Comments com in comment)
                {
                    context.Comments.Remove(com);
                }
                context.SaveChanges();
                userList = context.Users.ToList();
            }

            foreach (Users user in userList)
            {
                user.RoleName = GetRoleName(user.role_id);
            }

            return(View("UserList", userList));
        }
コード例 #12
0
        public void SetBet(string login, int race, string pos1, string pos2, string pos3, string time1)
        {
            using (ProjektEntities db = new ProjektEntities())
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        BETS itm = new BETS();
                        itm.User_ID = login;
                        itm.Date    = DateTime.Now.ToString();
                        itm.Race_ID = race;
                        itm.Pos_1   = pos1;
                        itm.Pos_2   = pos2;
                        itm.Pos_3   = pos3;
                        itm.Time_1  = time1;

                        db.BETS.Add(itm);
                        db.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    catch
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }
        }
コード例 #13
0
        // GET: Profil
        public ActionResult Index(string userID)
        {
            ProjektEntities db          = new ProjektEntities();
            UserManager     userManager = new UserManager();
            ProfileView     profileView = new ProfileView();

            if (userID == null)
            {
                userID = User.Identity.Name;
            }
            MyStaticValues.userName = userID;
            profileView.login       = userID;
            profileView.description = userManager.GetDescription(userID);
            profileView.imageData   = userManager.GetImage(userID);
            profileView.date_join   = userManager.GetDateJoin(userID);
            ViewBag.user            = userID;
            //Pobranie statystyk globalnych
            var GlobalStats = from i in db.USER
                              orderby i.Total_score descending
                              select new { i.User_ID, i.Total_score };

            profileView.global = new List <PointUserView>();

            //Wypełnienie danych statystyk globalnych
            foreach (var item in GlobalStats)
            {
                profileView.global.Add(new PointUserView {
                    login = item.User_ID, points = item.Total_score
                });
            }

            return(View(profileView));
        }
コード例 #14
0
 public bool IsEmailExist(string emailID)
 {
     using (ProjektEntities dc = new ProjektEntities())
     {
         var v = dc.Users.Where(a => a.email == emailID).FirstOrDefault();
         return(v != null);
     }
 }
コード例 #15
0
 public int UserId(string name)
 {
     using (ProjektEntities context = new ProjektEntities())
     {
         var user   = context.Users.Where(a => a.username == User.Identity.Name).FirstOrDefault();
         var userId = user.id;
         return(userId);
     }
 }
コード例 #16
0
 public string UserName(int?userId)
 {
     using (ProjektEntities context = new ProjektEntities())
     {
         var user     = context.Users.Where(a => a.id == userId).FirstOrDefault();
         var userName = user.username;
         return(userName);
     }
 }
コード例 #17
0
 public string GetRoleName(int?roleId)
 {
     using (ProjektEntities context = new ProjektEntities())
     {
         var    role     = context.Roles.Where(a => a.id == roleId).FirstOrDefault();
         string roleName = role.name;
         return(roleName);
     }
 }
コード例 #18
0
        public static string userTo;  // gdy napiszemy wiadomosc do uzytkownika A, wracamy ponownie do widoku z uzytkownikiem A
        public ActionResult Index(string userID)
        {
            ProjektEntities db = new ProjektEntities();

            var message = from m in db.MESSAGES  // wyswietlanie wiadomosci
                          where (m.Message_From == User.Identity.Name && m.Message_To == userID) || (m.Message_From == userID && m.Message_To == User.Identity.Name)
                          orderby m.Message_ID
                          select new { m.Message_From, m.Message_To, m.Content, m.Message_ID, m.Date };

            userTo = userID;

            var mod = new MessageListView
            {
                ListMessage      = new List <MessageView>(),
                ListUsersMessage = new List <MessageView>()
            };

            foreach (var item in message)   // dolaczenie wiadomosci do modelu, ktory jest wyswietlony
            {
                mod.ListMessage.Add(new MessageView {
                    fromUser = item.Message_From, toUser = item.Message_To, content = item.Content, messageID = item.Message_ID, date = item.Date
                });
            }


            var listUser = db.MESSAGES.Where(m => m.Message_From == User.Identity.Name)  // wybranie listy osob, do ktorych pisalismy(lista nie ma duplikatow)
                           .GroupBy(p => p.Message_To, (a, b) => b.OrderByDescending(e => e.Message_ID)).Select(s => s.FirstOrDefault());

            foreach (var item in listUser)   // dolaczenie uzytkownikow do modelu
            {
                mod.ListUsersMessage.Add(new MessageView {
                    toUser = item.Message_To, date = item.Date
                });
            }

            var listUser1 = db.MESSAGES.Where(m => m.Message_To == User.Identity.Name && m.Message_From != User.Identity.Name)  // wybranie listy osob, ktore do nas pisaly
                            .GroupBy(p => p.Message_From, (a, b) => b.OrderByDescending(e => e.Message_ID)).Select(s => s.FirstOrDefault());

            foreach (var item in listUser1)  // dolaczenie do modelu
            {
                mod.ListUsersMessage.Add(new MessageView {
                    toUser = item.Message_From, date = item.Date
                });
            }

            for (int i = 0; i < mod.ListUsersMessage.Count; i++)   // usuniecie duplikatow
            {
                for (int j = i + 1; j < mod.ListUsersMessage.Count; j++)
                {
                    if (mod.ListUsersMessage[i].toUser == mod.ListUsersMessage[j].toUser)
                    {
                        mod.ListUsersMessage.Remove(mod.ListUsersMessage[j]);
                    }
                }
            }
            return(View(mod));
        }
コード例 #19
0
        public ActionResult EditUser(string username)
        {
            using (ProjektEntities context = new ProjektEntities())
            {
                var user = context.Users.Where(a => a.username == username).FirstOrDefault();
                user.RoleCollection = context.Roles.ToList <Roles>();

                return(View(user));
            }
        }
コード例 #20
0
        // GET: Upload
        // GET: Upload
        //[Authorize]
        public ActionResult Upload()
        {
            Pictures picture = new Pictures();

            using (ProjektEntities context = new ProjektEntities())
            {
                picture.AlbumCollection = context.Albums.Where(a => a.visibility == 0).ToList <Albums>();
                // context.Albums.ToList<Albums>();
            }
            return(View(picture));
        }
コード例 #21
0
        public ActionResult VerifyAge()
        {
            var currentUserId = UserId(User.Identity.Name);

            using (ProjektEntities context = new ProjektEntities())
            {
                var user = context.Users.Where(a => a.id == currentUserId).FirstOrDefault();
                user.RoleCollection = context.Roles.ToList <Roles>();

                return(View());
            }
        }
コード例 #22
0
ファイル: UserManager.cs プロジェクト: damifil/WWW_MVC_BET
 public string GetDescription(string login)
 {
     using (ProjektEntities db = new ProjektEntities())
     {
         var user = db.USER.Where(o => o.User_ID.Equals(login));
         if (user.Any())
         {
             return(user.FirstOrDefault().Description);
         }
     }
     return(string.Empty);
 }
コード例 #23
0
ファイル: UserManager.cs プロジェクト: damifil/WWW_MVC_BET
 public byte[] GetImage(string login)
 {
     using (ProjektEntities db = new ProjektEntities())
     {
         var user = db.USER.Where(o => o.User_ID.Equals(login));
         if (user.Any())
         {
             return(user.FirstOrDefault().Image);
         }
     }
     return(null);
 }
コード例 #24
0
ファイル: UserManager.cs プロジェクト: damifil/WWW_MVC_BET
 public DateTime GetDateJoin(string login)
 {
     using (ProjektEntities db = new ProjektEntities())
     {
         var user = db.USER.Where(o => o.User_ID.Equals(login));
         if (user.Any())
         {
             return(user.FirstOrDefault().Date_join);
         }
     }
     return(DateTime.Now);
 }
コード例 #25
0
        public ActionResult Login(UserLogin login, string ReturnUrl = "")
        {
            string message = "";

            using (ProjektEntities dc = new ProjektEntities())
            {
                var v = dc.Users.Where(a => a.username == login.username).FirstOrDefault();
                if (v != null && login.password != null)
                {
                    if (!v.IsEmailVerified)
                    {
                        ViewBag.Message = "Please verify your email first";
                        return(View());
                    }


                    if (string.Compare(Crypto.Hash(login.password), v.password) == 0)
                    {
                        int    timeout   = login.RememberMe ? 525600 : 20; // 525600 min = 1 year
                        var    ticket    = new FormsAuthenticationTicket(login.username, login.RememberMe, timeout);
                        string encrypted = FormsAuthentication.Encrypt(ticket);
                        var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                        cookie.Expires  = DateTime.Now.AddMinutes(timeout);
                        cookie.HttpOnly = true;
                        Response.Cookies.Add(cookie);


                        if (Url.IsLocalUrl(ReturnUrl))
                        {
                            return(Redirect(ReturnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        message = "Invalid credential provided";
                    }
                }
                else
                {
                    message = "Invalid credential provided";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
コード例 #26
0
        public HomeModel PictureView(HomeModel homeModel, int gagId)
        {
            List <Albums>   albumList       = new List <Albums>();
            List <Pictures> pictureList     = new List <Pictures>();
            List <Comments> pictureComments = new List <Comments>();
            var             currentUserId   = 0;

            if (User.Identity.Name != "")
            {
                currentUserId = UserId(User.Identity.Name);
            }
            else
            {
                currentUserId = 0;
            }
            using (ProjektEntities context = new ProjektEntities())
            {
                var privates =
                    from a in context.Albums
                    where a.visibility == 1 && a.id_user == currentUserId
                    select a;

                var comments =
                    from c in context.Comments
                    join u in context.Users on c.id_user equals u.id into ps
                    where c.id_picture == gagId
                    select new { Comment = c, Users = ps };

                var sGag = context.Pictures.Where(a => a.id == gagId).FirstOrDefault();

                foreach (var comment in comments)
                {
                    pictureComments.Add(comment.Comment);
                }
                foreach (var category in privates)
                {
                    albumList.Add(category);
                }

                pictureList.Add(sGag);
                pictureList.Reverse();
                homeModel.pictureComments = pictureComments;
                homeModel.pictureList     = pictureList;
                homeModel.privateList     = albumList;


                return(homeModel);
            }
        }
コード例 #27
0
ファイル: UserManager.cs プロジェクト: damifil/WWW_MVC_BET
 public string GetUserPassword(string login)     //uzyskanie hasła danego użytkownika z bazy danych
 {
     using (ProjektEntities db = new ProjektEntities())
     {
         var user = db.USER.Where(u => u.User_ID.ToLower().Equals(login));
         if (user.Any())
         {
             return(user.FirstOrDefault().Password);
         }
         else
         {
             return(string.Empty);
         }
     }
 }
コード例 #28
0
        public ActionResult UserList()
        {
            List <Users> userList = new List <Users>();

            using (ProjektEntities context = new ProjektEntities())
            {
                userList = context.Users.ToList();
            }

            foreach (Users user in userList)
            {
                user.RoleName = GetRoleName(user.role_id);
            }

            return(View(userList));
        }
コード例 #29
0
        public ActionResult VerifyAge(Pesel pesel)
        {
            if (pesel.PeselNumber == null || pesel.BirthDate == null)
            {
                return(View());
            }
            else
            {
                var             currentUserId    = UserId(User.Identity.Name);
                List <Users>    userList         = new List <Users>();
                IPeselValidator peselValidator   = new PeselValidator();
                bool            checkPesel       = peselValidator.ValidatePesel(pesel.PeselNumber);
                bool            checkPeselAndAge = false;
                if (checkPesel == false)
                {
                    ViewBag.peselError = "Podany pesel jest niepoprawny";
                    return(View());
                }

                if (peselValidator.ValidateAge(pesel.BirthDate))
                {
                    checkPeselAndAge = peselValidator.ValidatePeselAndBirthDate(pesel.PeselNumber, pesel.BirthDate);
                }

                if (checkPeselAndAge)
                {
                    using (ProjektEntities context = new ProjektEntities())
                    {
                        var user = context.Users.Where(a => a.id == currentUserId).FirstOrDefault();
                        user.email           = user.email;
                        user.username        = user.username;
                        user.ConfirmPassword = user.password;
                        user.role_id         = 3;
                        context.SaveChanges();
                    }



                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewBag.peselError = "Podany pesel i data nie zgadzają się ze sobą";
                    return(View());
                }
            }
        }
コード例 #30
0
        public HomeModel IndexView(HomeModel homeModel)
        {
            List <Albums>   albumList     = new List <Albums>();
            List <Pictures> pictureList   = new List <Pictures>();
            List <Albums>   privateList   = new List <Albums>();
            var             currentUserId = 0;

            if (User.Identity.Name != "")
            {
                currentUserId = UserId(User.Identity.Name);
            }
            else
            {
                currentUserId = 0;
            }
            using (ProjektEntities context = new ProjektEntities())
            {
                var categoriesList = context.Albums.Where(a => a.visibility == 0).ToList <Albums>();
                var privatesList   =
                    from a in context.Albums
                    where a.visibility == 1 && a.id_user == currentUserId
                    select a;

                foreach (Pictures pic in context.Pictures)
                {
                    pictureList.Add(pic);
                    ViewBag.pic = pic.img;
                }

                foreach (Albums priv in privatesList)
                {
                    privateList.Add(priv);
                }

                foreach (Albums category in categoriesList)
                {
                    albumList.Add(category);
                }

                pictureList.Reverse();
                homeModel.pictureList = pictureList;
                homeModel.albumList   = albumList;
                homeModel.privateList = privateList;
            }
            return(homeModel);
        }