public JsonResult Slidesho(ViewAlbumModel rs) { SlideshoModel temp = new SlideshoModel() { src = new List <string>(), number = 0 }; if (db.Albums.Where(x => x.Id == rs.id).First().number != -1) { db.Albums.Where(x => x.Id == rs.id).First().number = -1; db.Albums.Where(x => x.Id == rs.id).First().Photos.ToList().ForEach( x => { temp.src.Add(x.Path); } ); db.SaveChanges(); return(Json(temp)); } else { db.Albums.Where(x => x.Id == rs.id).First().number = 0; temp.number = -1; db.SaveChanges(); return(Json(temp)); } }
public ActionResult ViewAlbum(int uid) { ViewAlbumModel temp = new ViewAlbumModel(); temp.id = uid; temp.number = 0; temp.src = db.Albums.Where(x => x.Id == uid).First().Photos.ToList()[temp.number].Path; return(View(temp)); }
public JsonResult Next(ViewAlbumModel rs) { if (db.Albums.Where(x => x.Id == rs.id).First().number == -1) { rs.number = db.Albums.Where(x => x.Id == rs.id).First().number = 0; } else if (db.Albums.Where(x => x.Id == rs.id).First().number < db.Albums.Where(x => x.Id == rs.id).First().Photos.Count - 1) { db.Albums.Where(x => x.Id == rs.id).First().number++; rs.number = db.Albums.Where(x => x.Id == rs.id).First().number; } else { rs.number = db.Albums.Where(x => x.Id == rs.id).First().number = 0; } db.SaveChanges(); rs.src = db.Albums.Where(x => x.Id == rs.id).First().Photos.ToList()[rs.number].Path; return(Json(rs)); }
public ActionResult SlideShow(int id) { ViewAlbumModel albumModel; using (PixurfDBContext db = new PixurfDBContext()) { Album album = db.Albums.Find(id); albumModel = new ViewAlbumModel { Album_ID = album.Album_ID, Name = album.Name, Description = album.Description, User = db.Users.Find(album.User_ID), Access = album.Access, Status = album.Status, Creation_Date = album.Creation_Date, Contents = album.Contents.ToList() }; } return(View(albumModel)); }
public ActionResult View(int id) { List <StatusReport> reports = new List <StatusReport>(); using (PixurfDBContext db = new PixurfDBContext()) { Album album = db.Albums.Find(id); if (album == null) { StatusReport report = new StatusReport { Title = "Error", Description = "Album not found", Status = StatusReport.Info }; reports.Add(report); Session["Reports"] = reports; return(RedirectToAction("Index", "Home")); } ViewAlbumModel albumModel = new ViewAlbumModel { Album_ID = album.Album_ID, Name = album.Name, Description = album.Description, User = db.Users.Find(album.User_ID), Access = album.Access, Status = album.Status, Creation_Date = album.Creation_Date, UserAuthenticated = false }; if (album.Status == 1) { if (album.User_ID == User.Identity.GetUserId()) { if (reports.Count > 0) { Session["Reports"] = reports; } albumModel.Contents = album.Contents.ToList(); albumModel.UserAuthenticated = true; return(View(albumModel)); } UserRelationship relationship = new UserRelationship(); //Private if (album.Access == "Private") { StatusReport report = new StatusReport { Title = "Access Denied", Description = "This Album is not accessible", Status = StatusReport.Warning }; reports.Add(report); Session["Reports"] = reports; return(RedirectToAction("Index", "Home")); } //Follower else if (album.Access == "Follower") { if (relationship.Following(album.User_ID, User.Identity.GetUserId())) { if (reports.Count > 0) { Session["Reports"] = reports; } var temp = album.Contents.Where(c => c.Access != "Private").ToList(); albumModel.Contents = temp; return(View(albumModel)); } else { StatusReport report = new StatusReport { Title = "Access Denied", Description = "Only Followers can view this Album", Status = StatusReport.Warning }; reports.Add(report); Session["Reports"] = reports; return(RedirectToAction("Index", "Home")); } } //Not Blocked else { if (relationship.Following(album.User_ID, User.Identity.GetUserId())) { if (reports.Count > 0) { Session["Reports"] = reports; } var temp = album.Contents.Where(c => c.Access != "Private").ToList(); albumModel.Contents = temp; return(View(albumModel)); } else if (!relationship.Blocked(album.User_ID, User.Identity.GetUserId())) { if (reports.Count > 0) { Session["Reports"] = reports; } var temp = album.Contents.Where(c => c.Access == "Public").ToList(); albumModel.Contents = temp; return(View(albumModel)); } StatusReport report = new StatusReport { Title = "Error", Description = "Album not found", Status = StatusReport.Warning }; reports.Add(report); Session["Reports"] = reports; return(RedirectToAction("Index", "Home")); } } else { User user = db.Users.Find(User.Identity.GetUserId()); if (user != null && user.Admin) { if (reports.Count > 0) { Session["Reports"] = reports; } albumModel.UserAuthenticated = true; return(View(albumModel)); } else { StatusReport report = new StatusReport { Title = "Error", Description = "Album not found", Status = StatusReport.Warning }; reports.Add(report); Session["Reports"] = reports; return(RedirectToAction("Index", "Home")); } } } }
public ActionResult Edit(ViewAlbumModel model) { List <StatusReport> reports = new List <StatusReport>(); string userId = User.Identity.GetUserId(); if (model != null && !model.Name.IsNullOrWhiteSpace() && !model.Access.IsNullOrWhiteSpace()) { using (PixurfDBContext db = new PixurfDBContext()) { //Find the Album Album album = db.Albums.Where(a => a.Album_ID == model.Album_ID) .OrderByDescending(a => a.Creation_Date).ToList().FirstOrDefault(); if (album == null) { reports.Add(new StatusReport { Title = "Error", Description = "Album not found", Status = StatusReport.Danger }); Session["Reports"] = reports; return(RedirectToAction("Index")); } User user = db.Users.Find(userId); if ((album.User_ID == userId && album.Status == 1) || (user != null && user.Admin)) { if (album.Name == model.Name && album.Description == model.Description && album.Access == model.Access) { reports.Add(new StatusReport { Title = "Success", Description = "No change is made", Status = StatusReport.Success }); Session["Reports"] = reports; return(RedirectToAction("View", "Album", new { id = album.Album_ID })); } else { album.Name = model.Name; album.Description = model.Description; album.Access = model.Access; try { db.SaveChanges(); reports.Add(new StatusReport { Title = "Success", Description = "Changes saved", Status = StatusReport.Success }); Session["Reports"] = reports; return(RedirectToAction("View", "Album", new { id = album.Album_ID })); } catch (Exception e) { Console.WriteLine(e); return(RedirectToAction("Index")); } } } } } return(View(model)); }
// So Far Complete public ActionResult AddNew(ViewAlbumModel model) { List <StatusReport> reports = new List <StatusReport>(); string userId = User.Identity.GetUserId(); if (model != null && !model.Name.IsNullOrWhiteSpace() && !model.Access.IsNullOrWhiteSpace()) { using (PixurfDBContext db = new PixurfDBContext()) { //Find the Album Album album = db.Albums.Where(a => a.Name == model.Name && a.Status != 0 && a.User_ID == userId).OrderByDescending(a => a.Creation_Date).ToList().FirstOrDefault(); //Create the album if its null if (album == null) { //Create an album album = new Album { Name = model.Name, Creation_Date = DateTime.Now, User_ID = userId, Access = model.Access, Status = 1, Description = model.Description }; db.Albums.Add(album); try { db.SaveChanges(); reports.Add(new StatusReport { Title = "Success", Description = "Album " + album.Name + " Successfully Created.", Status = StatusReport.Success }); Session["Reports"] = reports; } catch (Exception e) { reports.Add(new StatusReport { Title = "Error", Description = "Something went wrong", Status = StatusReport.Danger }); Session["Reports"] = reports; Console.WriteLine(e); } } else { //Already Exists reports.Add(new StatusReport { Title = "Failed", Description = "Album " + album.Name + " Already Exists.", Status = StatusReport.Warning }); Session["Reports"] = reports; } return(RedirectToAction("View", new { id = album.Album_ID })); } } return(View(model)); }
public ActionResult ViewAlbum() { ViewAlbumModel temp = new ViewAlbumModel(); return(View(temp)); }