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)));
        }
Exemplo n.º 2
0
 public IActionResult Create(ArtistCreate model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     _artistService.Create(model, User.FindFirst(ClaimTypes.NameIdentifier).Value);
     return(Ok());
 }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        public IHttpActionResult Post(ArtistCreate artist)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateArtistService();

            if (!service.CreateArtist(artist))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
Exemplo n.º 5
0
        //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);
            }
        }
Exemplo n.º 6
0
        //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);
            }
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        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
Exemplo n.º 9
0
        //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);
            }
        }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
0
        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));
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        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);
                }
            }
        }