Exemple #1
0
        public ActionResult New(UsersCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var Context = new ProjectDBEntities())
                {

                    var UserStatus = Context.UserStatus.Where(usx => usx.UserStatusDetail == "Pending").FirstOrDefault<UserStatu>();

                    model.DateCreated = DateTime.Now;
                    model.DateActivated = DateTime.Now;

                    Mapper.CreateMap<UsersCreateViewModel, SiteUser>();
                    SiteUser User = Mapper.Map<SiteUser>(model);


                    User.UserStatusID = UserStatus.UserStatusID;
                    User.UserPass = Hashing.CreateHash(model.UserPass);

                    Context.SiteUsers.Add(User);

                    if (Context.SaveChanges() == 1)
                        ViewBag.Message = "User added successfully..";
                    else
                        ViewBag.Message = "User cannot be added at the moment..";
                }
            }
            return View(new UsersCreateViewModel());
        }
Exemple #2
0
        public ActionResult ChangePassword(AdminChangePasswordViewModel model)
        {
            if(ModelState.IsValid)
            {
                if(User.Identity.IsAuthenticated && User.IsInRole("admin"))
                {
                    using(var Context = new ProjectDBEntities())
                    {
                        var OldHashedPassword = Hashing.CreateHash(model.OldPassword);

                        var user = Context.Administrators.Where(ax => ax.AdminUserName == User.Identity.Name && ax.AdminPassword == OldHashedPassword).FirstOrDefault<Administrator>();
                        if (user != null)
                        {
                            user.AdminPassword = Hashing.CreateHash(model.NewPassword);
                            Context.SaveChanges();
                            ViewBag.Message = "Password Changed Successfully to " + model.NewPassword;
                            return View(new AdminChangePasswordViewModel());
                        }
                        else
                        {
                            ViewBag.Message = "Old password seems different";
                            return View(new AdminChangePasswordViewModel());
                        }
                    }
                }
            }

            return Content(User.Identity.Name);
        }
Exemple #3
0
        public ActionResult Form(GenerePostForm model)
        {
            model.IsNew = model.GenereID == null;

            using (var Context = new ProjectDBEntities())
            {
                var validation = Context.Generes.Where(gx => gx.GenereDetail == model.Detail).FirstOrDefault<Genere>();
                if (validation != null)
                    ModelState.AddModelError("Detail", "This \"Genere\" already exist.. ");

                if (!ModelState.IsValid)
                    return View(model);

                if (model.IsNew)
                {
                    Genere genere = new Genere()
                    {
                        GenereDetail = model.Detail,
                        IsActive = model.IsActive
                    };

                    Context.Generes.Add(genere);
                }
                else
                {
                    var genere = Context.Generes.Where(nx => nx.GenereID == model.GenereID).FirstOrDefault<Genere>();
                    genere.GenereDetail = model.Detail;
                    genere.IsActive = model.IsActive;
                }

                Context.SaveChanges();
            }
            return RedirectToAction("Index");

        }
        public ActionResult Login(AdminLoginViewModel model)
        {
            if (User.Identity.IsAuthenticated && User.IsInRole("admin"))
                return RedirectToRoute(new { area = "manage", controller = "Admin", action = "Index" });
            else
            {
                if (!ModelState.IsValid)
                    return View(new AdminLoginViewModel());

                using (ProjectDBEntities Context = new ProjectDBEntities())
                {
                    model.Password = Hashing.CreateHash(model.Password);

                    var admin = Context.Administrators.Where(x => x.AdminUserName == model.Username && x.AdminPassword == model.Password).FirstOrDefault<Administrator>();

                    if (admin != null)
                    {
                        FormsAuthentication.SetAuthCookie(admin.AdminUserName, true);
                        return RedirectToRoute(new { area = "manage", controller = "Admin", action = "Index" });
                    }
                }

                ViewBag.Message = "Incorrect username/password combination..";
                return View(new AdminLoginViewModel());
            }
        }
Exemple #5
0
        public ActionResult Active(string userId)
        {
            try
            {
                Guid guid = Guid.Parse(userId);

                using (var Context = new ProjectDBEntities())
                {
                    var User = Context.SiteUsers.Where(sxu => sxu.UserID == guid).ToList();

                    if (User.Count > 0)
                    {
                        User[0].UserStatusID = 2;

                        if (Context.SaveChanges() == 1)
                            ViewBag.Message = "User status updated successfully..";
                        else
                            ViewBag.Message = "Unable to update user..";
                    }
                    else
                        ViewBag.Message = "No such user..";

                    return RedirectToAction("All");
                }
            }
            catch(Exception)
            {
                return HttpNotFound();
            }
        }
        public ActionResult ForgotPassword(AdminForgotPasswordViewModel model)
        {
            if(ModelState.IsValid)
            {
                using(var Context = new ProjectDBEntities())
                {
                    var admin = Context.Administrators.Where(x => x.AdminEmail == model.Email).FirstOrDefault<Administrator>();
                    if(admin==null)
                    {
                        ViewBag.Message = "No Such User..";
                        return View(model);
                    }

                    string generatedPassword = Hashing.GeneratePassword();
                    if (Mailer.ForgotPasswordAdmin(admin.AdminUserName, generatedPassword))
                    {

                        admin.AdminPassword = Hashing.CreateHash(generatedPassword);
                        Context.SaveChanges();
                        ViewBag.Message = "New Password has been sent to admin email..";
                        return View(new AdminForgotPasswordViewModel());
                    }
                    else
                    {
                        ViewBag.Message = "SMTP is not working.. try later..";
                        return View(new AdminForgotPasswordViewModel());
                    }

                }
            }

            return View(model);
        }
Exemple #7
0
        public ActionResult Find(string username)
        {
            var Context = new ProjectDBEntities();

            var user = Context.SiteUsers.Where(x => x.UserName == username).FirstOrDefault<SiteUser>();
            if (user == null)
                return HttpNotFound();

            return View(user);
        }
Exemple #8
0
        public ActionResult Index()
        {
            var Context = new ProjectDBEntities();
            
            AdminIndexViewModel model = new AdminIndexViewModel();

            model.Users = Context.SiteUsers.ToList();
            model.Tracks = Context.Tracks.ToList();
            model.Albums = Context.Albums.ToList();

            return View(model);
        }
Exemple #9
0
 public ActionResult Delete(int genereId)
 {
     using (var Context = new ProjectDBEntities())
     {
         if (!Context.Generes.Any(n => n.GenereID == genereId))
             return HttpNotFound();
         else
         {
             Context.Generes.Remove(Context.Generes.Where(nx => nx.GenereID == genereId).FirstOrDefault<Genere>());
             Context.SaveChanges();
         }
         return RedirectToAction("Index");
     }
 }
Exemple #10
0
        public ActionResult All()
        {
            using (ProjectDBEntities Context = new ProjectDBEntities())
            {
                List<SiteUser> SiteUsers = Context.SiteUsers.ToList();
                List<UsersCreateViewModel> ModelUsers = new List<UsersCreateViewModel>();

                Mapper.CreateMap<SiteUser, UsersCreateViewModel>();

                foreach (var user in SiteUsers)
                {
                    ModelUsers.Add(Mapper.Map<UsersCreateViewModel>(user));
                }

                return View(ModelUsers);
            }
        }
Exemple #11
0
        public ActionResult Show(int id, string slug)
        {
            using (var Context = new ProjectDBEntities())
            {
                var news = Context.News.Where(nx => nx.NewsID == id).FirstOrDefault<News>();
                if (news == null)
                    return HttpNotFound();

                if (!news.NewsSlug.Equals(slug) || news.IsDeleted)
                    return RedirectToAction("Index");

                return View(new NewsShow()
                {
                    News = news
                });
            }
        }
Exemple #12
0
        public ActionResult CreateAlbum()
        {
            var Context = new ProjectDBEntities();

            return View("AlbumForm", new CreateAlbumPostForm
            {
                IsNew = true,
                Generes = Context.Generes
                .Where(x => x.IsActive == true)
                .Select(genere => new GenereCheckBox
                {
                    ID = genere.GenereID,
                    Name = genere.GenereDetail,
                    IsChecked = false
                }).ToList()
            });
        }
Exemple #13
0
        public ActionResult Index(int page=1)
        {
            var Context = new ProjectDBEntities();

            var totalGeneresCount = Context.Generes.Count();


            var currentNewsPage = Context.Generes
                .OrderBy(x => x.GenereID)
                .Skip((page - 1) * GenerePerPage)
                .Take(GenerePerPage)
                .ToList();

            return View(new GenereIndex
            {
                Genere = new PageData<Genere>(currentNewsPage, totalGeneresCount, page, GenerePerPage)
            });
        }
Exemple #14
0
        public ActionResult EditProfile()
        {
            using (var Context = new ProjectDBEntities())
            {
                var user = Context.SiteUsers
                    .Where(x => x.UserName == User.Identity.Name)
                    .FirstOrDefault<SiteUser>();

                return View(new EditProfileViewModel
                {
                    ID = user.UserID,
                    FirstName = user.UserFirstName,
                    MiddleName = user.UserMiddleName,
                    LastName = user.UserLastName,
                    Email = user.UserEmail
                });
            }
        }
Exemple #15
0
        public ActionResult Index()
        {
            var Context = new ProjectDBEntities();
            
            IndexDisplayViewModel model = new IndexDisplayViewModel();

            if (User.Identity.IsAuthenticated)
            {
                var Tracks = from t in Context.Tracks
                             join ts in Context.UserTrackShares on t.TrackID equals ts.TrackID
                             where ts.SharingType.SharingTypeDetail == "Public" || ts.SharingType.SharingTypeDetail == "Users Only"
                             select t;

                foreach (var item in Tracks)
                {
                    var LikesCount = item.UserTrackShares.Select(x => x.UserTrackShareLikes.Count()).ToList();
                    item.LikesCount = LikesCount[0];
                }

                model.Tracks = Tracks.ToList();
            }
            else
            {
                var Tracks = from t in Context.Tracks
                             join ts in Context.UserTrackShares on t.TrackID equals ts.TrackID
                             where ts.SharingType.SharingTypeDetail == "Public"
                             select t;

                foreach (var item in Tracks)
                {
                    var LikesCount = item.UserTrackShares.Select(x => x.UserTrackShareLikes.Count()).ToList();
                    item.LikesCount = LikesCount[0];
                }

                model.Tracks = Tracks.ToList();
            }

            model.Albums = Context.Albums
                .Where(x => x.IsActive == true && x.Tracks.Count > 0 && x.AlbumTitle != "Default")
                .OrderByDescending(x => x.AlbumGeneres.Count)
                .ToList();

            return View(model);
        }
Exemple #16
0
        public ActionResult Index(int page =1)
        {
            using(var Context = new ProjectDBEntities())
            {
                var DatabaseQuery = Context.News.Where(nx => nx.DeleteDate == null).OrderByDescending(nx => nx.PostedDate);

                var TotalNewsCount = DatabaseQuery.Count();

                if (page == 0)
                    page = 1;

                var NewsIDs = DatabaseQuery.Skip((page - 1) * NewsPerPage).Take(NewsPerPage).Select(t => t.NewsID).ToArray();
                var News = DatabaseQuery.Where(t => NewsIDs.Contains(t.NewsID)).ToList();

                return View(new NewsIndex()
                {
                    News = new PageData<News>(News, TotalNewsCount, page, NewsPerPage)
                });
            }
        }
Exemple #17
0
        public ActionResult Index(int page = 1)
        {

            var Context = new ProjectDBEntities();

            var totalNewsCount = Context.News.Count();


            var currentNewsPage = Context.News
                .OrderBy(x => x.PostedDate)
                .Skip((page - 1) * NewsPerPage)
                .Take(NewsPerPage)
                .ToList();

            return View(new NewsIndexViewModel
                       {
                           News = new PageData<News>(currentNewsPage, totalNewsCount, page, NewsPerPage)
                       });

        }
Exemple #18
0
        public ActionResult Form(PostForm model)
        {
            model.IsNew = model.NewsID == null;

            if (!ModelState.IsValid)
                return View(model);


            using (var Context = new ProjectDBEntities())
            {
                var adminGuid = (Context.Administrators.Where(ax => ax.AdminUserName == User.Identity.Name).FirstOrDefault<Administrator>()).AdminID;

                if (model.IsNew)
                {

                    News news = new News()
                    {
                        NewsTitle = model.Title,
                        NewsSlug = model.Slug,
                        NewsContents = model.Contents,
                        PostedBy = adminGuid,
                        PostedDate = DateTime.UtcNow
                    };

                    Context.News.Add(news);
                    
                }
                else
                {
                    var news = Context.News.Where(nx => nx.NewsID == model.NewsID).FirstOrDefault<News>();
                    news.NewsTitle = model.Title;
                    news.NewsSlug = model.Slug;
                    news.NewsContents = model.Contents;
                    news.PostedDate = DateTime.UtcNow;
                    news.PostedBy = adminGuid;
                }
                Context.SaveChanges();
            }
            return RedirectToAction("Index");

        }
Exemple #19
0
        public ActionResult Index(int page = 1)
        {
            if (page == 0)
                page = 1;

            var Context = new ProjectDBEntities();

            var totalAlbumsCount = Context.Albums.Count();

            var currentAlbumPage = Context.Albums
                .Where(x => x.IsActive == true && x.AlbumTitle != "Default" && x.Tracks.Count > 0)
                .OrderBy(x => x.DateAdded)
                .Skip((page - 1) * PerPage)
                .Take(PerPage)
                .ToList();

            return View(new AlbumsListViewModel
            {
                Albums = new PageData<Album>(currentAlbumPage, totalAlbumsCount, page, PerPage)
            });
        }
Exemple #20
0
        public ActionResult EditAlbum(Guid id)
        {
            using (var Context = new ProjectDBEntities())
            {
                var album = Context.Albums.Where(tx => tx.AlbumID == id).FirstOrDefault<Album>();

                if (album == null)
                    return HttpNotFound();

                IList<GenereCheckBox> generes = new List<GenereCheckBox>();

                foreach (var item in Context.Generes.Where(g => g.IsActive == true).ToList())
                {
                    var itemIsSelected = Context.AlbumGeneres
                        .Where(x => x.GenereID == item.GenereID && x.AlbumID == album.AlbumID)
                        .FirstOrDefault<AlbumGenere>();

                    bool isChecked = false;

                    if (itemIsSelected != null)
                        isChecked = true;

                    generes.Add(new GenereCheckBox
                    {
                        ID = item.GenereID,
                        Name = item.GenereDetail,
                        IsChecked = isChecked
                    });
                }

                return View("AlbumForm", new CreateAlbumPostForm()
                {
                    IsNew = false,
                    Title = album.AlbumTitle,
                    AlbumID = album.AlbumID,
                    IsActive = album.IsActive,
                    Generes = generes
                });
            }
        }
Exemple #21
0
        public ActionResult EditProfile(EditProfileViewModel model)
        {
            if(!ModelState.IsValid)
            {
                return View(model);
            }

            using (var Context = new ProjectDBEntities())
            {
                var user = Context.SiteUsers.Where(x => x.UserName == User.Identity.Name).FirstOrDefault<SiteUser>();

                if (user.UserID != model.ID)
                {
                    ViewBag.Message = "You cannot edit others profile..";
                    return View(model);
                }

                var userEmailValidation = Context.SiteUsers
                    .Where(x => x.UserEmail == model.Email && x.UserID != user.UserID)
                    .FirstOrDefault<SiteUser>();

                if (userEmailValidation != null)
                {
                    ViewBag.Message = "There is already a user with same email";
                    return View(model);
                }

                user.UserFirstName = model.FirstName;
                user.UserMiddleName = model.MiddleName;
                user.UserLastName = model.LastName;
                user.UserEmail = model.Email;

                Context.SaveChanges();
                ViewBag.Message = "Profile edited Successfully..";

                return View(model);
            }

        }
Exemple #22
0
        public static bool NotifyNewPassword(string username, string password)
        {
            try
            {
                Guid guid = Guid.Parse(username);
                using (var Context = new ProjectDBEntities())
                {
                    var user = Context.SiteUsers.Where(ux => ux.UserID == guid).FirstOrDefault<SiteUser>();

                    var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
                    var message = new MailMessage();
                    message.To.Add(new MailAddress(user.UserEmail));
                    message.From = new MailAddress("*****@*****.**");
                    message.Subject = "Your email subject";
                    message.Body = string.Format(body, "Music Library Official", "*****@*****.**", "Your new Password is " + password);
                    message.IsBodyHtml = true;

                    using (var smtp = new SmtpClient())
                    {
                        var credential = new NetworkCredential
                        {
                            UserName = "******",
                            Password = "******"
                        };
                        smtp.Credentials = credential;
                        smtp.Host = "smtp-mail.outlook.com";
                        smtp.Port = 587;
                        smtp.EnableSsl = true;
                        smtp.Send(message);
                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Exemple #23
0
        public static bool ForgotPasswordAdmin(string username, string password)
        {
            try
            {
                using (var Context = new ProjectDBEntities())
                {
                    var user = Context.Administrators.Where(x => x.AdminUserName == username).FirstOrDefault<Administrator>();

                    var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
                    var message = new MailMessage();
                    message.To.Add(new MailAddress(user.AdminEmail));
                    message.From = new MailAddress("*****@*****.**");
                    message.Subject = "Your email subject";
                    message.Body = string.Format(body, "Music Library Official", "*****@*****.**", "Your new Password for username : "******" is \"" + password + "\"");
                    message.IsBodyHtml = true;

                    using (var smtp = new SmtpClient())
                    {
                        var credential = new NetworkCredential
                        {
                            UserName = "******",
                            Password = "******"
                        };
                        smtp.Credentials = credential;
                        smtp.Host = "smtp-mail.outlook.com";
                        smtp.Port = 587;
                        smtp.EnableSsl = true;
                        smtp.Send(message);
                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Exemple #24
0
 public ActionResult Edit(int id)
 {
     using (var Context = new ProjectDBEntities())
     {
         var genere = Context.Generes.Where(nx => nx.GenereID == id).FirstOrDefault<Genere>();
         return View("Form", new GenerePostForm()
         {
             IsNew = false,
             GenereID = genere.GenereID,
             Detail = genere.GenereDetail,
             IsActive = genere.IsActive
         });
     }
 }
Exemple #25
0
 public ActionResult Edit(int id)
 {
     using(var Context = new ProjectDBEntities())
     {
         var news = Context.News.Where(nx => nx.NewsID == id).FirstOrDefault<News>();
         return View("Form", new PostForm()
             {
                 NewsID = news.NewsID,
                 IsNew = false,
                 Title = news.NewsTitle,
                 Slug = news.NewsSlug,
                 Contents = news.NewsContents
             });
     }
 }
Exemple #26
0
        public ActionResult Restore(int newsId)
        {
            using (var Context = new ProjectDBEntities())
            {
                var news = Context.News.Where(nx => nx.NewsID == newsId).FirstOrDefault<News>();
                if (news == null)
                    return HttpNotFound();

                news.DeleteDate = null;
                Context.SaveChanges();

                return RedirectToAction("Index");
            }
        }
Exemple #27
0
        public ActionResult ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
                return View(model);

            using (var Context = new ProjectDBEntities())
            {
                var oldPassword = Hashing.CreateHash(model.OldPassword);
                var user = Context.SiteUsers
                    .Where(x => x.UserName == User.Identity.Name && x.UserPass == oldPassword)
                    .FirstOrDefault<SiteUser>();

                if (user == null)
                {
                    ViewBag.Message = "Old password doesn't match..";
                    return View(model);
                }

                user.UserPass = Hashing.CreateHash(model.NewPassword);

                Context.SaveChanges();

                ViewBag.Message = "Password Changed Successfully..";
                return View(new ChangePasswordViewModel());
            }
        }
Exemple #28
0
        public ActionResult Restore(int genereId)
        {
            using (var Context = new ProjectDBEntities())
            {
                var news = Context.Generes.Where(nx => nx.GenereID == genereId).FirstOrDefault<Genere>();
                if (news == null)
                    return HttpNotFound();

                news.IsActive = true;
                Context.SaveChanges();

                return RedirectToAction("Index");
            }
        }
Exemple #29
0
        public ActionResult ResetPassword(string userId)
        {
            try
            {
                Guid guid = Guid.Parse(userId);
                using (var Context = new ProjectDBEntities())
                {
                    var User = Context.SiteUsers.Where(sxu => sxu.UserID == guid).FirstOrDefault<SiteUser>();

                    if (User != null)
                    {
                        UsersResetPasswordViewModel Model = new UsersResetPasswordViewModel();
                        Model.UserID = User.UserID;
                        Model.UserPass = Hashing.GeneratePassword();
                        return View(Model);
                    }
                    else
                        return HttpNotFound();
                }
            }
            catch(Exception)
            {
                return HttpNotFound();
            }
        }
Exemple #30
0
        public ActionResult ResetPassword(string userId, UsersResetPasswordViewModel model)
        {
            try
            {
                Guid guid = Guid.Parse(userId);

                using (var Context = new ProjectDBEntities())
                {
                    var User = Context.SiteUsers.Where(sxu => sxu.UserID == guid).FirstOrDefault<SiteUser>();

                    if (User != null)
                    {
                        if (Mailer.NotifyNewPassword(userId, model.UserPass))
                        {
                            User.UserPass = Hashing.CreateHash(model.UserPass);
                            Context.SaveChanges();
                        }
                        else
                        {
                            model.UserID = guid;
                            ModelState.AddModelError("Email", "SMTP Not working..");
                            return View(model);
                        }
                    }
                    else
                        return HttpNotFound();
                }

                return RedirectToAction("All");
            }
            catch(Exception)
            {
                return HttpNotFound();
            }
        }