public void Create_Increses_Count_Of_Albums() { var currentCount = db.Albums.Count(); underTest.Create(new Album() { Name = "Random Name", ImageName = "Random Image", ReleaseYear = 4, RecordLabel = "Random Label", Genre = "Random Genre", ArtistId = 1 }); var endCount = db.Albums.Count(); Assert.Equal(currentCount + 1, endCount); }
public JsonResult Create(Album album) { Response.BufferOutput = true; try { repoAlbum.Create(album); repoAlbum.Save(); //Created Response.StatusCode = 201; //Set Location header to absolute path of entity. Response.AddHeader("LOCATION", Request.Url.AbsoluteUri + "/" + album.id); return(this.Json(new { success = true, data = album }, JsonRequestBehavior.DenyGet)); } catch { return(this.Json(new { success = false }, JsonRequestBehavior.DenyGet)); } }
private static void CreateAlbums() { UserRepository users = new UserRepository(); UserModel user = users.GetByUsername("Klocu"); AlbumRepository albums = new AlbumRepository(); CategoryModel category=null; using (var session = SessionProvider.SessionFactory.OpenSession()) { category=session.CreateQuery("from CategoryModel where Name =:name").SetParameter("name","People").UniqueResult<CategoryModel>(); } AlbumModel album = new AlbumModel() { Category = category, CommentsAllow = true, CommentsAuth = false, Description = "Jak zmieniałem się w czasie", Name = "Moja twarz", Public = true, Rating = 0, User = user, Views = 1234 }; albums.Create(album); LinkedList<PhotoModel> list = new LinkedList<PhotoModel>(); PhotoModel photo = new PhotoModel() { Album = album, Date = new DateTime(2011, 1, 1, 22, 33, 5), Description = "Oto ja", Path = "/Static/photos/photo_2012051022444645.jpg" }; list.AddLast(photo); photo = new PhotoModel() { Album = album, Date = new DateTime(2011,4,30,22,33,5), Description = "Oto ja", Path = "/Static/photos/photo_2012051022450267.jpg" }; list.AddLast(photo); photo = new PhotoModel() { Album = album, Date = new DateTime(2012, 2,28 , 1, 8, 59), Description = "Oto ja", Path = "/Static/photos/photo_2012051022452109.jpg" }; list.AddLast(photo); photo = new PhotoModel() { Album = album, Date = new DateTime(2011, 1, 8, 1, 8, 59), Description = "Oto ja", Path = "/Static/photos/20110108.jpg" }; list.AddLast(photo); photo = new PhotoModel() { Album = album, Date = new DateTime(2011, 1, 15, 1, 8, 59), Description = "Oto ja", Path = "/Static/photos/20110115.jpg" }; list.AddLast(photo); photo = new PhotoModel() { Album = album, Date = new DateTime(2011, 1, 22, 1, 8, 59), Description = "Oto ja", Path = "/Static/photos/20110122.jpg" }; list.AddLast(photo); photo = new PhotoModel() { Album = album, Date = new DateTime(2011, 1, 29, 1, 8, 59), Description = "Oto ja", Path = "/Static/photos/20110129.jpg" }; list.AddLast(photo); album = new AlbumModel() { Category = category, CommentsAllow = true, CommentsAuth = false, Description = "", Name = "Widok za moin oknem", Public = true, Rating = 0, User = user, Views = 2 }; albums.Create(album); photo = new PhotoModel() { Album = album, Date = new DateTime(2011, 4, 30, 22, 33, 5), Description = "Oto ja", Path = "/Static/photos/2011-12-29 06.48.45.jpg" }; list.AddLast(photo); photo = new PhotoModel() { Album = album, Date = new DateTime(2011, 4, 30, 22, 33, 5), Description = "Oto ja", Path = "/Static/photos/2012-04-30 18.07.20.jpg" }; list.AddLast(photo); photo = new PhotoModel() { Album = album, Date = new DateTime(2011, 4, 30, 22, 33, 5), Description = "Oto ja", Path = "/Static/photos/2012-04-30 18.07.35.jpg" }; list.AddLast(photo); album = new AlbumModel() { Category = category, CommentsAllow = true, CommentsAuth = false, Description = "Zmieniający się rynek", Name = "Zmieniający się rynek", Public = true, Rating = 0, User = user, Views = 111 }; albums.Create(album); photo = new PhotoModel() { Album = album, Date = new DateTime(2011, 4, 30, 22, 33, 5), Description = "Oto ja", Path = "/Static/photos/2011-12-29 06.48.45.jpg" }; list.AddLast(photo); photo = new PhotoModel() { Album = album, Date = new DateTime(2011, 4, 30, 22, 33, 5), Description = "Oto ja", Path = "/Static/photos/2012-04-30 18.07.20.jpg" }; list.AddLast(photo); photo = new PhotoModel() { Album = album, Date = new DateTime(2011, 4, 30, 22, 33, 5), Description = "Oto ja", Path = "/Static/photos/2012-04-30 18.07.35.jpg" }; list.AddLast(photo); /* album = new AlbumModel() { Category = category, CommentsAllow = true, CommentsAuth = false, Description = "Jak zmieniałem się w czasie", Name = "Moja twarz", Public = true, Rating = 0, User = user, Views = 1234 }; */ using(var session= SessionProvider.SessionFactory.OpenSession()) using (var trans = session.BeginTransaction()) { foreach (PhotoModel p in list) session.Save(p); trans.Commit(); } }
public IActionResult Create([FromBody] Album album) { AlbumRepository repo = new AlbumRepository(_configuration); return(Ok(repo.Create(album))); }
public ActionResult Create(AlbumModel newAlbum) { PrepareCategories(); SetNextNotification(newAlbum); // private access SetPrivateAccess(newAlbum); if (ModelState.IsValid) { //assign a current user UserRepository users = new UserRepository(); newAlbum.User = users.GetByUsername(HttpContext.User.Identity.Name); AlbumRepository albums = new AlbumRepository(); albums.Create(newAlbum); return RedirectToAction("Show", new { id = newAlbum.Id }); } return View(newAlbum); }