public ActionResult OthersAlbum() { OtherAlbumModel otherAlbumModel = new OtherAlbumModel(); otherAlbumModel.albums = new List <Album>(); for (int i = 0; i < 5 && i < db.Albums.Count(); i++) { otherAlbumModel.albums.Add(db.Albums.ToList()[db.Albums.ToList().Count - 1 - i]); } return(View(otherAlbumModel)); }
public JsonResult ChoiceCount(OtherAlbumModel rs) { // db.Configuration.ProxyCreationEnabled = false; rs.albums = new List <Album>(); if (rs.count != "All") { int count = int.Parse(rs.count); for (int i = 0; i < count && i < db.Albums.Count(); i++) { var my_db = db.Albums.ToList()[i]; var my_photo = my_db.Photos; var elem = new Album() { Id = my_db.Id, Name = my_db.Name, number = my_db.number, Photos = new List <Photo>(), User = new User() { Id = my_db.User.Id, Login = my_db.User.Login, Password = my_db.User.Password } }; foreach (var elem_photo in my_photo) { elem.Photos.Add(new Photo() { Id = elem_photo.Id, Name = elem_photo.Name, Path = elem_photo.Path, UpLoad = elem_photo.UpLoad }); } rs.albums.Add(elem); } } else if (rs.count == "All") { for (int i = 0; i < db.Albums.Count(); i++) { var my_db = db.Albums.ToList()[i]; var my_photo = my_db.Photos; var elem = new Album() { Id = my_db.Id, Name = my_db.Name, number = my_db.number, Photos = new List <Photo>(), User = new User() { Id = my_db.User.Id, Login = my_db.User.Login, Password = my_db.User.Password } }; foreach (var elem_photo in my_photo) { elem.Photos.Add(new Photo() { Id = elem_photo.Id, Name = elem_photo.Name, Path = elem_photo.Path, UpLoad = elem_photo.UpLoad }); } rs.albums.Add(elem); } } // db.Configuration.ProxyCreationEnabled = true; // string JSONString = string.Empty; // JSONString = JsonConvert.SerializeObject(rs); //return Json(JSONString); return(Json(rs, JsonRequestBehavior.AllowGet)); // string json = JsonConvert.SerializeObject(rs, Formatting.Indented); // return Json(json); }