コード例 #1
0
        public async Task <IActionResult> Edit(int?id)
        {
            //validate id
            if (id == null)
            {
                return(new NotFoundViewResult("_Error404"));
                //TODO in case of items we could just send a message
            }
            try
            {
                var item = await _premiumRepository.GetByIdWithIncludesAsync(id.Value);

                if (item == null)
                {
                    return(new NotFoundViewResult("_Error404"));
                }

                var model = _converter.ToPremiumOfferViewModel(item);

                return(PartialView("_Edit", model));
            }
            catch (Exception)
            {
                return(new NotFoundViewResult("_Error500"));
            }
        }
コード例 #2
0
        public async Task <IActionResult> GetOffersImageFile(int id)
        {
            var offer = await _premiumRepository.GetByIdWithIncludesAsync(id);

            FileResult imageUserFile = GetFileFromBytes(offer.Image);

            return(imageUserFile);
        }
コード例 #3
0
        public async Task <IActionResult> PremiumDetails(int?id)
        {
            try
            {
                if (id == null)
                {
                    throw new Exception("This item was not found!");
                }

                var model = await _premiumRepository.GetByIdWithIncludesAsync(id.Value);

                if (model == null)
                {
                    throw new Exception("This item was not found!");
                }

                return(View(_converterHelper.ToPremiumOfferViewModel(model)));
            }
            catch (Exception e)
            {
                TempData["ErrorMessage"] = e.Message;
                return(RedirectToAction(nameof(Index)));
            }
        }