Ejemplo n.º 1
0
        public IActionResult SelectMainPicture(int currentMainPictureId, string returnUrl)
        {
            return(TryGetActionResult(() =>
            {
                if (string.IsNullOrEmpty(returnUrl))
                {
                    return BadRequest();
                }

                var picturesResult = _attachmentService.GetPicturesExcept(currentMainPictureId);

                if (picturesResult.Status != ServiceResponseStatus.Success)
                {
                    TempData["Error"] = "Не удалось получить изображения.";
                    return Redirect(returnUrl);
                }

                var picturesModels = _mapper.Map <IEnumerable <MainPictureViewModel> >(picturesResult.Result);
                var viewModel = new SelectMainPictureViewModel
                {
                    ReturnUrl = returnUrl,
                    Pictures = picturesModels.ToList()
                };

                return View(viewModel);
            }, ex =>
            {
                TempData["Error"] = "Не удалось получить изображения.";
                return Redirect(returnUrl);
            }));
        }
Ejemplo n.º 2
0
        public IActionResult Select(SelectMainPictureViewModel model)
        {
            return(TryGetActionResult(() =>
            {
                if (model.SelectedID > 0)
                {
                    if (_memoryCache.TryGetValue(CacheKeys.SelectMainPictureCacheKey, out BaseCreateUpdateViewModel cachedModel))
                    {
                        cachedModel.MainPicture = model.Pictures.Single(p => p.ID == model.SelectedID);
                        _memoryCache.Set(CacheKeys.SelectMainPictureCacheKey, cachedModel);
                        Session.SetBool(CacheKeys.SelectMainPictureCacheValidKey, true);
                    }
                    else
                    {
                        return BadRequest();
                    }
                }
                else
                {
                    Session.SetBool(CacheKeys.SelectMainPictureCacheValidKey, true);
                }

                return Redirect(model.ReturnUrl);
            }, ex =>
            {
                TempData["Error"] = "Не удалось выбрать изображение.";
                return Redirect(model.ReturnUrl);
            }));
        }
Ejemplo n.º 3
0
        public IActionResult Cancel(SelectMainPictureViewModel model)
        {
            Session.SetBool(CacheKeys.SelectMainPictureCacheValidKey, true);

            return(Redirect(model.ReturnUrl));
        }