Esempio n. 1
0
        public ShellViewModel()
        {
            Navigation = new NavigationViewModel(_events);
            Search     = new SearchViewModel(_events);
            Art        = new ArtViewModel();
            Status     = new StatusViewModel();
            ActionTabs = new ActionTabsViewModel();

            Navigation.Events.Subscribe(ActionTabs);
            Search.Events.Subscribe(ActionTabs);
            Title = "Kermit";
        }
        public IActionResult Edit(int id)
        {
            ViewBag.id = id;
            Art          art   = service.GetDetails(id);
            ArtViewModel model = new ArtViewModel();

            model.Name        = art.Name;
            model.Price       = art.Price;
            model.TypeOfArt   = art.TypeOfArt;
            model.Description = art.Description;
            return(View(model));
        }
Esempio n. 3
0
        public ActionResult Index(string id)
        {
            // news data
            Exhibit ex = ExhibitsDb.GetNews(db);

            if (ex != null)
            {
                if (ex.Gallery.Count() > 0)
                {
                    ViewBag.NewsPath = ex.Gallery.Last().Path;
                }

                ViewBag.NewsName = ex.Name;
            }

            // Exhibits
            ArtViewModel vm = new ArtViewModel();

            vm.Exhibits   = ExhibitsDb.GetExhibitMap(db);
            vm.Paintings  = ArtsDb.GetAllPaintings(db);
            vm.Sculptures = ArtsDb.GetAllSculptures(db);

            // Gallery
            if (id != null)
            {
                Exhibit show = ExhibitsDb.GetExhibit(db, id);
                if (show != null)
                {
                    vm.Gallery = show.Gallery;
                }
                else
                {
                    vm.Gallery = ArtsDb.GetArtsByName(db, id);
                }
            }
            else
            {
                Exhibit show = ExhibitsDb.GetNews(db);
                if (show != null)
                {
                    vm.Gallery = show.Gallery;
                }
            }

            return(View(vm));
        }
        public IActionResult Add(ArtViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            Art art = new Art();

            art.Name        = model.Name;
            art.Price       = model.Price;
            art.TypeOfArt   = model.TypeOfArt;
            art.dateTime    = DateTime.Now;
            art.Description = model.Description;
            art.UserID      = manager.GetUserId(HttpContext.User);
            try
            {
                service.Add(art);
                string uniqueFileName = null;
                if (model.Photos != null && model.Photos.Count > 0)
                {
                    foreach (IFormFile photo in model.Photos)
                    {
                        string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                        uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName;
                        string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                        photo.CopyTo(new FileStream(filePath, FileMode.Create));
                        ArtPhoto artPhoto = new ArtPhoto();
                        artPhoto.Path  = uniqueFileName;
                        artPhoto.ArtID = art.ID;
                        photoService.Add(artPhoto);
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(model));
            }
            return(RedirectToAction("ShowDetails", new { id = art.ID }));
        }
        public IActionResult Edit(int id, ArtViewModel model)
        {
            ViewBag.id = id;
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            Art art = new Art();

            art.Name        = model.Name;
            art.Price       = model.Price;
            art.Description = model.Description;
            art.TypeOfArt   = model.TypeOfArt;
            try
            {
                service.Update(id, art);
                string uniqueFileName = null;
                if (model.Photos != null && model.Photos.Count > 0)
                {
                    photoService.Delete(id);
                    foreach (IFormFile photo in model.Photos)
                    {
                        string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                        uniqueFileName = Guid.NewGuid().ToString() + "_" + photo.FileName;
                        string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                        photo.CopyTo(new FileStream(filePath, FileMode.Create));
                        ArtPhoto artPhoto = new ArtPhoto();
                        artPhoto.Path  = uniqueFileName;
                        artPhoto.ArtID = id;
                        photoService.Add(artPhoto);
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(model));
            }
            return(RedirectToAction("ShowDetails", new { id = id }));
        }