Exemple #1
0
        public ActionResult Create(OwnerInventoryListViewModel ownerInvDetails)
        {
            var artistId  = getNextArtistId(ownerInvDetails.Name);
            var artworkId = getNextArtworkId();
            var ipId      = getNextIpId();

            using (Context _context = new Context())
            {
                if (ModelState.IsValid)
                {
                    Artist artist = new Artist
                    {
                        Name      = ownerInvDetails.Name,
                        ArtistId  = artistId,
                        BirthYear = ownerInvDetails.BirthYear
                    };
                    _context.Artist.Add(artist); // saves data to the context
                    _context.SaveChanges();      // saves data to database
                }

                if (ModelState.IsValid)
                {
                    ArtWork artwork = new ArtWork
                    {
                        ArtWorkId = artworkId,
                        Title     = ownerInvDetails.Title,
                        ArtistId  = artistId,
                        Category  = ownerInvDetails.Category
                    };
                    _context.ArtWork.Add(artwork); // saves data to the context
                    _context.SaveChanges();        // saves data to database
                }

                if (ModelState.IsValid)
                {
                    IndividualPiece ip = new IndividualPiece
                    {
                        IndividualPieceId = ipId,
                        ArtWorkId         = artworkId,
                        Cost     = ownerInvDetails.Cost,
                        Price    = ownerInvDetails.Price,
                        Sold     = ownerInvDetails.Sold,
                        Location = ownerInvDetails.Location,
                    };
                    _context.IndividualPiece.Add(ip); // saves data to the context
                    _context.SaveChanges();           // saves data to database
                }
            }

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        // GET: Owner/Edit/5
        public ActionResult Edit(int ipId)
        {
            using (Context _context = new Context())
            {
                var ipDetails = (from ip in _context.IndividualPiece
                                 join aw in _context.ArtWork
                                 on ip.ArtWorkId equals aw.ArtWorkId
                                 join ar in _context.Artist
                                 on aw.ArtistId equals ar.ArtistId
                                 where ip.IndividualPieceId == ipId
                                 select new OwnerInventoryViewModel
                {
                    Image = ip.Image,
                    Cost = ip.Cost,
                    Price = ip.Price,
                    Sold = ip.Sold,
                    Location = ip.Location,
                    IndividualPieceId = ip.IndividualPieceId,
                    EditionNumber = ip.EditionNumber,
                    Name = ar.Name,
                    Title = aw.Title,
                    NumberInInventory = aw.NumberInInventory
                }).ToList();

                OwnerInventoryListViewModel ownerInventoryModel = new OwnerInventoryListViewModel
                {
                    Name              = ipDetails.Select(a => a.Name).FirstOrDefault(),
                    Title             = ipDetails.Select(a => a.Title).FirstOrDefault(),
                    Image             = ipDetails.Select(a => a.Image).FirstOrDefault(),
                    Price             = ipDetails.Select(a => a.Price).FirstOrDefault(),
                    Cost              = ipDetails.Select(a => a.Cost).FirstOrDefault(),
                    Sold              = ipDetails.Select(a => a.Sold).FirstOrDefault(),
                    IndividualPieceId = ipDetails.Select(a => a.IndividualPieceId).FirstOrDefault()
                };

                return(View(ownerInventoryModel));
            }
        }
Exemple #3
0
        public ActionResult Edit(OwnerInventoryListViewModel ownerInvDetails)
        {
            {
                using (Context _context = new Context())
                {
                    var IndvP = _context.IndividualPiece.Find(ownerInvDetails.IndividualPieceId);
                    if (ModelState.IsValid)
                    {
                        IndvP.Price    = ownerInvDetails.Price;
                        IndvP.Cost     = ownerInvDetails.Cost;
                        IndvP.Sold     = ownerInvDetails.Sold;
                        IndvP.Location = ownerInvDetails.Location;

                        _context.SaveChanges();
                    }

                    var Artist = _context.Artist.Find(ownerInvDetails.ArtistId);
                    if (ModelState.IsValid)
                    {
                        Artist.Name = ownerInvDetails.Name;

                        _context.SaveChanges();
                    }

                    var Artwork = _context.ArtWork.Find(ownerInvDetails.ArtWorkId);
                    if (ModelState.IsValid)
                    {
                        Artwork.Title = ownerInvDetails.Title;

                        _context.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    return(View(ownerInvDetails));
                }
            }
        }