public ActionResult Create(ArtistCreate model) { if (!ModelState.IsValid) { return(View(model)); } var artistEntity = new Artist { ArtistName = model.ArtistName, Albums = model.Albums?.Select(i => new Album { AlbumTitle = i.AlbumTitle, ReleaseDate = i.ReleaseDate }).ToList() }; var context = new ApplicationDbContext(); context.Artists.Add(artistEntity); var itemCount = model.Albums is null ? 0 : model.Albums.Count; var expectedChangeCount = 1 + itemCount; if (context.SaveChanges() != expectedChangeCount) { return(View(model)); } return(RedirectToAction(nameof(Index))); }
public IActionResult Create(ArtistCreate model) { if (!ModelState.IsValid) { return(BadRequest()); } _artistService.Create(model, User.FindFirst(ClaimTypes.NameIdentifier).Value); return(Ok()); }
public void Create(ArtistCreate model, string userId) { var entity = new Artist { Birthday = model.Birthday, FirstName = model.FirstName, Country = model.Country, LastName = model.LastName, UserId = userId }; _dbContext.Artists.Add(entity); _dbContext.SaveChanges(); }
public IHttpActionResult Post(ArtistCreate artist) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateArtistService(); if (!service.CreateArtist(artist)) { return(InternalServerError()); } return(Ok()); }
//Crud public bool CreateArtist(ArtistCreate model) { var entity = new Artist() { // UserID = _userID, ArtistName = model.ArtistName, Location = model.Location }; using (var ctx = new ApplicationDbContext()) { ctx.Artists.Add(entity); return(ctx.SaveChanges() == 1); } }
//CreateArtist public bool CreateArtist(ArtistCreate model) { var artist = new Artist() { Name = model.Name, IsBand = model.IsBand, CountryOfOrigin = model.CountryOfOrigin }; using (var ctx = new ApplicationDbContext()) { ctx.Artists.Add(artist); return(ctx.SaveChanges() == 1); } }
public bool CreateArtist(ArtistCreate model) { var entity = new Artist() { ArtistName = model.ArtistName, Birthdate = model.Birthdate }; using (var ctx = new ApplicationDbContext()) { ctx.Artists.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateArtist(ArtistCreate model) { var entity = new Artist() { OwnerId = _userId, ArtistName = model.ArtistName, ArtistRating = model.ArtistRating }; using (var ctx = new ApplicationDbContext()) { ctx.Artists.Add(entity); return(ctx.SaveChanges() == 1); } } // CreateArtist
//private readonly Guid _userId; //public ArtistService(Guid userId) //{ // _userId = userId; //} public bool CreateArtist(ArtistCreate model) { var entity = new Artist() { //OwnerId = _userId, ArtistName = model.ArtistName, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Artists.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateArtist(ArtistCreate model) { var entity = new Artist() { OwnerId = _userId, ArtistName = model.ArtistName, NumberOfMembers = model.NumberOfMembers, Genre = model.Genre }; using (var ctx = new ApplicationDbContext()) { ctx.Artists.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateArtist(ArtistCreate model) { var entity = new Artist() { ArtistName = model.ArtistName, ShopID = model.ShopID, Shop = model.Shop, ArtistContact = model.ArtistContact }; using (var ctx = new ApplicationDbContext()) { ctx.Artists.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(ArtistCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = new ArtistService(); if (service.CreateArtist(model)) { TempData["SaveResult"] = "Artist has been added"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Artist was not added"); return(View(model)); }
public ActionResult Create(ArtistCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateArtistService(); if (service.CreateArtist(model)) { TempData["SaveResult"] = "Artist was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Artist could not be created"); return(View(model)); }
public ActionResult Create(ArtistCreate model) { var db = new ShopService(); ViewBag.ShopID = new SelectList(db.GetShops().ToList(), "ShopID", "ShopName"); if (!ModelState.IsValid) { return(View(model)); } var service = new ArtistService(); if (service.CreateArtist(model)) { TempData["SaveResult"] = "Artist added."; return(RedirectToAction("Create", "Post")); } ModelState.AddModelError("", "Artist could not be added."); return(View(model)); }
public Artist CreateArtist(ArtistCreate model) { var entity = new Artist() { ArtistName = model.ArtistName }; using (var db = new ApplicationDbContext()) { db.Artists.Add(entity); if (db.SaveChanges() == 1) { return(entity); } else { return(null); } } }