Exemplo n.º 1
0
        // GET: CardInfo
        public ActionResult Details(int id)
        {
            var repo  = CardInfoRepositoryFactory.GetRepository();
            var model = repo.GetDetails(id);

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Edit(CardInfoEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var repo        = CardInfoRepositoryFactory.GetRepository();
                var oldCardInfo = repo.GetById(model.CardInfo.CardId);
                try
                {
                    if (oldCardInfo.CardArtURL != model.ImageUpload.FileName)
                    {
                        var savepath = Server.MapPath("~/Images");

                        string fileName  = Path.GetFileNameWithoutExtension(model.ImageUpload.FileName);
                        string extension = Path.GetExtension(model.ImageUpload.FileName);

                        var filePath = Path.Combine(savepath, fileName + extension);

                        int counter = 1;
                        while (System.IO.File.Exists(filePath))
                        {
                            filePath = Path.Combine(savepath, fileName + counter.ToString() + extension);
                            counter++;
                        }
                        model.ImageUpload.SaveAs(filePath);
                        model.CardInfo.CardArtURL = Path.GetFileName(filePath);

                        var oldPath = Path.Combine(savepath, oldCardInfo.CardArtURL);
                        if (System.IO.File.Exists(oldPath))
                        {
                            System.IO.File.Delete(oldPath);
                        }
                    }
                    repo.Update(model.CardInfo);

                    return(RedirectToAction("Edit", new { id = model.CardInfo.CardId }));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                var setsRepo = SetsRepositoryFactory.GetRepository();
                model.Sets = new SelectList(setsRepo.GetAll(), "SetId", "SetName");
                var artistsRepo = ArtistRepositoryFactory.GetRepository();
                model.Artists = new SelectList(artistsRepo.GetAll(), "ArtistId", "ArtistName");
                return(View(model));
            }
        }
Exemplo n.º 3
0
        public ActionResult Edit(int id)
        {
            var model = new CardInfoEditViewModel();

            var setsRepo     = SetsRepositoryFactory.GetRepository();
            var artistsRepo  = ArtistRepositoryFactory.GetRepository();
            var cardInfoRepo = CardInfoRepositoryFactory.GetRepository();

            model.Sets     = new SelectList(setsRepo.GetAll(), "SetId", "SetName");
            model.Artists  = new SelectList(artistsRepo.GetAll(), "ArtistId", "ArtistName");
            model.CardInfo = cardInfoRepo.GetById(id);

            //if(user is not admin)
            //{
            //   throw new Exception("Only the admin can edit");
            //}

            return(View(model));
        }
        public IHttpActionResult Search(decimal?minPrice, decimal?maxPrice, string cardName, string setName, string colorName)
        {
            var repo = CardInfoRepositoryFactory.GetRepository();

            try
            {
                var parameters = new CardInfoSearchParameters()
                {
                    MinPrice  = minPrice,
                    MaxPrice  = maxPrice,
                    CardName  = cardName,
                    SetName   = setName,
                    ColorName = colorName
                };
                var result = repo.Search(parameters);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemplo n.º 5
0
        public ActionResult Index()
        {
            var model = CardInfoRepositoryFactory.GetRepository().GetMostExpensive();

            return(View(model));
        }