예제 #1
0
        public async Task <IActionResult> PutArtPiece(int id, ArtPiece artPiece)
        {
            if (id != artPiece.ArtPieceId)
            {
                return(BadRequest());
            }

            _context.Entry(artPiece).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArtPieceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("ArtPieceId,Author,Info,ModifiedDate,AuthorsNote,TypeOfArt,Style,Reserved,PictureFile,Price,Horizontal")] ArtPiece artPiece)
        {
            if (ModelState.IsValid)
            {
                string wwwRootPath = _hostEnvironment.WebRootPath;
                string fileName    = Path.GetFileNameWithoutExtension(artPiece.PictureFile.FileName);
                string extension   = Path.GetExtension(artPiece.PictureFile.FileName);
                artPiece.PicUrl = fileName = fileName + DateTime.Now.ToString("yymmss") + extension;
                string path = Path.Combine(wwwRootPath + "/StoredPictures/", fileName);

                try
                {
                    using (var fileStream = new FileStream(path, FileMode.Create))
                    {
                        await artPiece.PictureFile.CopyToAsync(fileStream);
                    }
                    _context.Add(artPiece);
                    await _context.SaveChangesAsync();

                    Message   = $"Art {artPiece.Info} added";
                    ArtAction = "Create";
                }
                catch (DbUpdateException)
                {
                    return(View("Error"));
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(artPiece));
        }
예제 #3
0
        public async Task <ActionResult <ArtPiece> > PostArtPiece(ArtPiece artPiece)
        {
            _context.ArtPiece.Add(artPiece);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetArtPiece", new { id = artPiece.ArtPieceId }, artPiece));
        }
        public GalleryElementDetailsViewModel(ITextAssetsRepository textRepository, ArtPiece artPiece, string returnUrl, HttpContext context)
            : base(textRepository)
        {
            LabelValueDict = new Dictionary <string, string>();

            ArtPiece  = artPiece;
            ImageUri  = artPiece.ImageUri;
            ForSale   = artPiece.ForSale;
            ReturnUrl = returnUrl;

            if (textRepository.GetTranslatedValue(artPiece.Name, context) != null)
            {
                LabelValueDict[textRepository.GetTranslatedValue("name", context)] =
                    TextRepository.GetTranslatedValue(artPiece.Name, context);
            }
            if (textRepository.GetTranslatedValue(artPiece.Description, context) != null)
            {
                LabelValueDict[textRepository.GetTranslatedValue("description", context)] =
                    TextRepository.GetTranslatedValue(artPiece.Description, context);
            }
            LabelValueDict[textRepository.GetTranslatedValue("technique", context)] =
                textRepository.GetTranslatedValue(artPiece.Technique.Name, context);
            if (artPiece.CreationDate != null)
            {
                LabelValueDict[textRepository.GetTranslatedValue("creation_date", context)] =
                    artPiece.CreationDate;
            }
            if (textRepository.GetTranslatedValue(artPiece.AdditionalInfo, context) != null)
            {
                LabelValueDict[textRepository.GetTranslatedValue("additional_info", context)] =
                    TextRepository.GetTranslatedValue(artPiece.AdditionalInfo, context);
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("ArtPieceId,Author,Info,ModifiedDate,AuthorsNote,TypeOfArt,Style,Reserved,PicUrl,Horizontal,Price")] ArtPiece artPiece)
        {
            if (id != artPiece.ArtPieceId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(artPiece);
                    await _context.SaveChangesAsync();

                    Message   = $"Art {artPiece.Info} edited";
                    ArtAction = "Edit";
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ArtPieceExists(artPiece.ArtPieceId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(artPiece));
        }
예제 #6
0
        public ArtPiece TrackArtPiece(int numberToAdd)
        {
            ArtPiece art   = new ArtPiece();
            ArtPiece trial = new ArtPiece();
            int      count = Data.ArtPieces.Count() + 1;


            string newID = art.ArtPieceId.ToString();

            for (int x = 0; x < newID.Length; x++)
            {
                numberToAdd *= 10;
            }
            art.ArtPieceId = numberToAdd + count;
            while (Data.ArtPieces.Find(art.ArtPieceId) != null)
            {
                art.ArtPieceId = art.ArtPieceId * 10;
            }
            Data.Database.OpenConnection();
            try
            {
                Data.Add(art);
                Data.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.ArtPieces ON");

                Data.SaveChanges();
                Data.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.ArtPieces OFF");
            }
            finally
            {
                Data.Database.CloseConnection();
            }
            return(art);
        }
예제 #7
0
        static private void NewSearch(char type)
        {
            string id;

            Console.Clear();
            Console.WriteLine("------ New Search ------ \n");
            switch (type)
            {
            case 'A':
                Console.Write("Type the artistID you want to search:");
                id = Console.ReadLine();
                Console.WriteLine();
                Artist a = gal.SearchArtist(id);
                if (a != null)
                {
                    Console.WriteLine(a.ToString());
                }
                else
                {
                    Console.WriteLine("ID not found!");
                }
                break;

            case 'C':
                Console.Write("Type the curatorID you want to search:");
                id = Console.ReadLine();
                Console.WriteLine();
                Curator c = gal.SearchCurator(id);
                if (c != null)
                {
                    Console.WriteLine(c.ToString());
                }
                else
                {
                    Console.WriteLine("ID not found!");
                }
                break;

            case 'P':
                Console.Write("Type the pieceID you want to search:");
                id = Console.ReadLine();
                Console.WriteLine();
                ArtPiece p = gal.SearchArtPiece(id);
                if (p != null)
                {
                    Console.WriteLine(p.ToString());
                }
                else
                {
                    Console.WriteLine("ID not found!");
                }
                break;
            }
            Console.WriteLine();
            Console.WriteLine("Press any key to continue.");
            Console.ReadLine();
        }
예제 #8
0
        public ArtPiece GetArtPiece(int id)
        {
            ArtPiece artPiece = Data.ArtPieces.Where(A => A.ArtPieceId == id).FirstOrDefault();

            if (artPiece == null)
            {
                return(null);
            }
            artPiece.Themes = Data.ArtThemes.Where(At => At.ArtPieceId == id).ToList();
            return(artPiece);
        }
예제 #9
0
    public void OnRecievedArt(ObjectToTransfer art)
    {
        if (!ArtBook.ContainsKey(art.PlayerID))
        {
            ArtPiece SpawnedArt = Instantiate <GameObject>(SpawnedArtPiece, Vector3.zero, Quaternion.identity).GetComponent <ArtPiece>();
            SpawnedArt.SetArt(art.GetTexture(), MeshArts[art.ObjectID]);
            ArtBook.Add(art.PlayerID, SpawnedArt);

            if (Players.ContainsKey(art.PlayerID))
            {
                Players[art.PlayerID].SetArtPiece(SpawnedArt);
            }
        }
    }
예제 #10
0
        public void changeArtThemes(ArtPiece art, string themeString)
        {
            if (themeString == "")
            {
                return;
            }
            var currentThemes = Data.ArtThemes.Where(l => l.ArtPieceId == art.ArtPieceId).ToArray();
            var NewThemeArray = themeString.Split(",");

            int[] actions = new int[currentThemes.Length];

            /*First Nested For Loop Checks to See What Themes Must be removed*/
            for (int x = 0; x < currentThemes.Length; x++)
            {
                var reject = true;
                for (int y = 0; y < NewThemeArray.Length; y++)
                {
                    if (currentThemes[x].ThemeName == NewThemeArray[y])
                    {
                        reject = false;
                    }
                }
                if (reject == true)
                {
                    Console.WriteLine(currentThemes[x].ThemeName + " Was Removed");
                    Data.Remove(currentThemes[x]);
                }
            }
            //Second For Loop checks to see what themes need to be added
            for (int x = 0; x < NewThemeArray.Length; x++)
            {
                var add = true;
                for (int y = 0; y < currentThemes.Length; y++)
                {
                    if (currentThemes[y].ThemeName == NewThemeArray[x])
                    {
                        add = false;
                    }
                }
                if (add == true)
                {
                    Data.Add(new ArtThemes {
                        ThemeName = NewThemeArray[x], ArtPieceId = art.ArtPieceId
                    });
                    Console.WriteLine(NewThemeArray[x] + " Was Added");
                }
            }
            Data.SaveChanges();
        }
예제 #11
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ArtPiece = await _context.ArtPieces.FirstOrDefaultAsync(m => m.Id == id);

            if (ArtPiece == null)
            {
                return(NotFound());
            }
            return(Page());
        }
예제 #12
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ArtPiece = await _context.ArtPieces.FindAsync(id);

            if (ArtPiece != null)
            {
                _context.ArtPieces.Remove(ArtPiece);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
예제 #13
0
        public CreateResultDTO CreateArtPiece(CreateArtPieceData create)
        {
            if (create.SuppliesNeeded == "" || create.Title == "")
            {
                return(null);
            }
            ArtPiece ArtPieceToAdd = TrackArtPiece(1);

            themeManager.ConnectEntity(create.Themes, ArtPieceToAdd.ArtPieceId, "Art");

            ArtPieceToAdd.Title           = create.Title;
            ArtPieceToAdd.ImageURL        = create.ImageURL;
            ArtPieceToAdd.SuppliesNeeded  = create.SuppliesNeeded;
            ArtPieceToAdd.DocumentBlobURL = create.WritingURL;
            Data.SaveChanges();
            return(new CreateResultDTO
            {
                id = ArtPieceToAdd.ArtPieceId,
                imageURL = ArtPieceToAdd.ImageURL
            });
        }
예제 #14
0
        private void DeletePiece_Click(object sender, RoutedEventArgs e)
        {
            piecesText.Text = "";

            if (pieceID.Text == "")
            {
                MessageBox.Show("Art Piece ID is required!");
                return;
            }
            ArtPiece p = gal.DeleteArtPiece(pieceID.Text);

            if (p != null)
            {
                piecesText.Text  = "Art Piece deleted!\n";
                piecesText.Text += p.ToString();
            }
            else
            {
                MessageBox.Show("Art Piece ID not registred!");
                return;
            }
        }
예제 #15
0
        private void addArtPiece_Click(object sender, RoutedEventArgs e)
        {
            if (pieceID.Text == "" || pieceTitle.Text == "" || pieceYear.Text == "" || pieceEstimate.Text == "" || pieceArtistID.Text == "" || pieceCuratorID.Text == "")
            {
                MessageBox.Show("All fields are required!");
                return;
            }

            if (!fieldsValidation("id", pieceID))
            {
                MessageBox.Show("Invalid ID!\nID should have 5 characteres.");
                return;
            }
            if (!fieldsValidation("pieceTitle", pieceTitle))
            {
                MessageBox.Show("Invalid Name!\nName must have maximum 40 characteres.");
                return;
            }
            if (!fieldsValidation("pieceYear", pieceYear))
            {
                MessageBox.Show("Invalid Year!\nYear must have 4 digits.");
                return;
            }
            if (!fieldsValidation("pieceEstimate", pieceEstimate))
            {
                MessageBox.Show("Invalid Estimate Value!\nValue must be a number.");
                return;
            }

            piecesText.Text = "";
            ArtPiece p = gal.SearchArtPiece(pieceID.Text);

            if (p != null)
            {
                MessageBox.Show("Piece ID already exists!");
                return;
            }

            Artist a = gal.SearchArtist(pieceArtistID.Text);

            if (a == null)
            {
                MessageBox.Show("Artist ID doesn`t exists!");
                return;
            }
            Curator c = gal.SearchCurator(pieceCuratorID.Text);

            if (c == null)
            {
                MessageBox.Show("Curator ID doesn`t exists!");
                return;
            }

            p = gal.AddArtPiece(pieceID.Text, pieceTitle.Text, pieceYear.Text, double.Parse(pieceEstimate.Text), pieceArtistID.Text, pieceCuratorID.Text);
            if (pieceInStorage.IsChecked == true)
            {
                gal.SetStatus(pieceID.Text, 'O');
            }
            if (pieceOnDisplay.IsChecked == true)
            {
                gal.SetStatus(pieceID.Text, 'D');
            }

            piecesText.Text  = "Art Piece added!\n";
            piecesText.Text += p.ToString();

            //Clear fields
            pieceID.Text        = "";
            pieceTitle.Text     = "";
            pieceYear.Text      = "";
            pieceEstimate.Text  = "";
            pieceArtistID.Text  = "";
            pieceCuratorID.Text = "";
        }
예제 #16
0
 public ArtPiece Update(ArtPiece artPiece)
 {
     throw new NotImplementedException();
 }
        public ActionResult SignUp(CurrentCustomersViewModel ccvm)
        {
            var artId = ccvm.artId;
            // Get access to the piece sold
            var PieceSold = (from ap in _context.ArtPiece

                             join aw in _context.ArtWork
                             on ap.IdArtWork equals aw.IdArtWork

                             where ap.IdArtPiece == ccvm.artId
                             select new
            {
                artID = ap.IdArtPiece,
                Title = aw.ArtWorkTitle
            }).Single();

            // Get access to the customer and agent involved in the sale
            var custAndAgentID = (from c in _context.Customer

                                  join ag in _context.Agent
                                  on c.IdAgent equals ag.IdAgent

                                  where c.IdCustomer == ccvm.SelectedCustID
                                  select new CustAndAgentViewModel
            {
                cust = c.IdCustomer,
                agent = ag.IdAgent,
                PaymentMethod = "Visa",
                ShippingAddress = c.CustomerAddress,
                PieceSold = PieceSold.Title
            }).Single();

            // Create a new Invoice
            Invoice _invoice = new Invoice
            {
                IdCustomer      = ccvm.SelectedCustID,
                IdAgent         = custAndAgentID.agent,
                PaymentMethod   = custAndAgentID.PaymentMethod,
                ShippingAddress = custAndAgentID.ShippingAddress,
                PieceSold       = custAndAgentID.PieceSold
            };

            _context.Invoice.Add(_invoice);
            _context.SaveChanges();

            // Get access to the invoice you just created to connect it to the InvoiceArtPiece and InvoiceLineItem Tables
            var InvoiceId = (from i in _context.Invoice
                             orderby i.IdInvoice
                             select new InvoiceIdViewModel
            {
                ID = i.IdInvoice
            }).ToList().Last();

            InvoiceArtPiece iap = new InvoiceArtPiece
            {
                IdInvoice  = InvoiceId.ID,
                IdArtPiece = ccvm.artId
            };

            _context.InvoiceArtPiece.Add(iap);
            _context.SaveChanges();

            // Access the ArtPiece to update that it has been sold

            var _ap = (from ap in _context.ArtPiece
                       where ap.IdArtPiece == ccvm.artId
                       select new ArtPieceUpdateViewModel
            {
                IdArtPiece = ap.IdArtPiece,
                ArtPieceSold = true,
                ArtPieceDateCreated = ap.ArtPieceDateCreated,
                ArtPieceEditionNum = ap.ArtPieceEditionNum,
                ArtPieceImage = ap.ArtPieceImage,
                ArtPieceLocation = ap.ArtPieceLocation,
                ArtPiecePrice = ap.ArtPiecePrice,
                IdArtWork = ap.IdArtWork
            }).Single();
            // Create a new local ArtPiece to send and update the database table
            ArtPiece AP = new ArtPiece
            {
                ArtPieceDateCreated = _ap.ArtPieceDateCreated,
                ArtPieceEditionNum  = _ap.ArtPieceEditionNum,
                ArtPieceImage       = _ap.ArtPieceImage,
                ArtPieceLocation    = _ap.ArtPieceLocation,
                ArtPiecePrice       = _ap.ArtPiecePrice,
                ArtPieceSold        = _ap.ArtPieceSold,
                IdArtPiece          = _ap.IdArtPiece,
                IdArtWork           = _ap.IdArtWork
            };


            //_context.Entry(AP).State = EntityState.Modified;
            _context.ArtPiece.Attach(AP);
            _context.Entry(AP).State = EntityState.Modified;
            _context.SaveChanges();
            return(RedirectToAction("Inventory"));
        }
예제 #18
0
 public void SetArtPiece(ArtPiece OwnedPiece)
 {
     OwnedArtPiece = OwnedPiece;
 }
        public ActionResult AddPainting(AddArtViewModel Art)
        {
            // Set the instance of a local view model to set the ID of either the existing artist, or the new artist we will create
            ArtistViewModel local_artist = new ArtistViewModel();

            if (ModelState.IsValid)
            {
                // If the artist the user entered already exists, use that artist's ID
                var _artistNameCheck = (from a in _context.Artist
                                        select new
                {
                    IdArtist = a.IdArtist,
                    ArtistName = a.ArtistName
                }).ToList();

                bool NameCheck = false;
                foreach (var item in _artistNameCheck)
                {
                    if (item.ArtistName == Art.newArtist.ArtistName)
                    {
                        NameCheck = true;
                    }
                }


                // This is the case where the artist already exists in the database
                if (NameCheck == true)
                {
                    // Set a new instance of a private artist with the properties from the database
                    var _artist = (from a in _context.Artist
                                   where a.ArtistName == Art.newArtist.ArtistName
                                   select new ArtistViewModel
                    {
                        ID = a.IdArtist
                    }).Single();
                    local_artist = _artist;
                }
                else
                {
                    //Since this is a new Artist: Set local artist model to the data set by the user, passed into the add paiting override method.
                    Artist artist = new Artist
                    {
                        ArtistName      = Art.newArtist.ArtistName,
                        ArtistBirthYear = Art.newArtist.ArtistBirthYear,
                        ArtistDeathYear = Art.newArtist.ArtistDeathYear
                    };
                    _context.Artist.Add(artist);
                    _context.SaveChanges();

                    var _artist = (from a in _context.Artist
                                   where a.ArtistName == Art.newArtist.ArtistName
                                   select new ArtistViewModel
                    {
                        ID = a.IdArtist
                    }).Single();
                    local_artist = _artist;
                }


                //Set a private variable = to the artist the user just created.

                //Set local artwork model to the data set by the user, passed into the add paiting override method.
                ArtWork artwork = new ArtWork
                {
                    IdArtist            = local_artist.ID,
                    ArtWorkDimensions   = Art.ArtWork.ArtWorkDimensions,
                    ArtWorkTitle        = Art.ArtWork.ArtWorkTitle,
                    ArtWorkYear         = Art.ArtWork.ArtWorkYear,
                    ArtWorkMedium       = Art.ArtWork.ArtWorkMedium,
                    ArtWorkNumMade      = 1,
                    ArtWorkNumInventory = 1,
                    ArtWorkNumSold      = 0
                };
                _context.ArtWork.Add(artwork);
                _context.SaveChanges();

                //Set a private variable = to the artwork the user just created.
                var _artWork = (from aw in _context.ArtWork
                                where aw.ArtWorkTitle == Art.ArtWork.ArtWorkTitle
                                select new
                {
                    IdArtWork = aw.IdArtWork,
                }).Single();

                //Set local artpiece model to the data set by the user, passed into the AddPaiting override method.
                ArtPiece artPiece = new ArtPiece
                {
                    IdArtWork           = _artWork.IdArtWork,
                    ArtPieceImage       = Art.ArtPiece.ArtPieceImage,
                    ArtPieceDateCreated = Art.ArtPiece.ArtPieceDateCreated,
                    ArtPiecePrice       = Art.ArtPiece.ArtPiecePrice,
                    ArtPieceSold        = false,
                    ArtPieceLocation    = Art.ArtPiece.ArtPieceLocation,
                    ArtPieceEditionNum  = 1
                };
                _context.ArtPiece.Add(artPiece);
                _context.SaveChanges();

                return(RedirectToAction("Inventory"));
            }

            return(View());
        }
예제 #20
0
        private void Test()
        {
            _auctionMock = new Mock<DbSet<Auction>>();
            _lotMock = new Mock<DbSet<Lot>>();
            _artPieceMock = new Mock<DbSet<ArtPiece>>();
            _mockContext = new Mock<AuctionContext>();

            _mockContext.Setup(m => m.Auctions).Returns(_auctionMock.Object);
            _mockContext.Setup(m => m.Lots).Returns(_lotMock.Object);
            _mockContext.Setup(m => m.ArtPieces).Returns(_artPieceMock.Object);

            _artPiece = new ArtPiece()
            {
                ArtPieceId = 1,
                Artist = "Anders",
                Description = "Hej",
                Name = "Mona Lisa",
                Number = 1001,
                PurchasePrice = 10
            };

            _lot = new Lot()
            {
                LotId = 1,
                MinBid = 20,
                Position = 1,
                ArtPiece = _artPiece
            };

            _auction = new Auction
            {
                AuctionId = 1,
                AuctionName = "Test Auction",
                CreationDate = DateTime.Now,
                LotDuration = TimeSpan.FromMinutes(30),
                Multiplier = 3,
                Status = Status.Ready,
                Lots = new List<Lot>() { _lot }
            };

            var data = new List<Auction>
            {
                _auction
            }.AsQueryable();

            _auctionMock.As<IQueryable<Auction>>().Setup(m => m.Provider).Returns(data.Provider);
            _auctionMock.As<IQueryable<Auction>>().Setup(m => m.Expression).Returns(data.Expression);
            _auctionMock.As<IQueryable<Auction>>().Setup(m => m.ElementType).Returns(data.ElementType);
            _auctionMock.As<IQueryable<Auction>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
        }