Ejemplo n.º 1
0
        public async Task <IActionResult> CreateOrEdit([FromForm] MovieViewModel movieVm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (movieVm.Id != 0)
            {
                var movieRes = await _movieService.GetMovie(movieVm.Id);

                if (!movieRes.IsSuccess)
                {
                    return(RedirectToAction("Details", new { id = movieVm.Id, showSuccessMessage = false }));
                }
                var movie = movieRes.Data;
                if (!await _userManager.CheckEditPermissionAsync(User, movie))
                {
                    return(Forbid());
                }
            }

            var currentUser = await _userManager.GetUserAsync(User);

            var result = await _movieService.AddOrEditMovie(movieVm.ToModel(), movieVm.NewPoster, currentUser);

            if (result.IsSuccess)
            {
                return(RedirectToAction("Details", new { id = result.Data.Id, showSuccessMessage = result.IsSuccess }));
            }

            movieVm.Message          = OperationResultHelper.GetMessage(result.IsSuccess);
            movieVm.IsSuccessMessage = false;
            return(View(movieVm));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Delete(MovieViewModel movieVm)
        {
            var result = await _movieService.GetMovie(movieVm.Id);

            if (!result.IsSuccess)
            {
                return(RedirectToAction("Index", new { pageNumber = 1, isSuccess = false }));
            }

            var movie = result.Data;

            if (!await _userManager.CheckEditPermissionAsync(User, movie))
            {
                return(Forbid());
            }

            var isDeleted = await _movieService.DeleteMovie(movie);

            if (isDeleted)
            {
                return(RedirectToAction("Index", new { id = 1, isSuccess = true }));
            }

            movieVm.Message          = OperationResultHelper.GetMessage(isSuccess: false);
            movieVm.IsSuccessMessage = false;
            return(View(movieVm));
        }
Ejemplo n.º 3
0
        protected override IOperationResult ProcessResponse(BinaryResponse response)
        {
            var result = new BinaryOperationResult();

            return(response.StatusCode == 0
                                ? result.Pass()
                                : result.Fail(OperationResultHelper.ProcessResponseData(response.Data)));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Index(int pageNumber = 1, bool?isSuccess = null)
        {
            var model = await _movieService.GetMoviePage(pageNumber);

            if (isSuccess.HasValue)
            {
                model.Message          = OperationResultHelper.GetMessage(isSuccess.Value);
                model.IsSuccessMessage = isSuccess.Value;
            }

            return(View(model));
        }
        protected override IOperationResult ProcessResponse(BinaryResponse response)
        {
            var status = response.StatusCode;
            var result = new BinaryOperationResult();

            this.StatusCode = status;
            if (status == 0)
            {
                int flags = BinaryConverter.DecodeInt32(response.Extra, 0);
                this.result = new CacheItem((ushort)flags, response.Data);
                this.Cas    = response.CAS;

                return(result.Pass());
            }

            this.Cas = 0;
            return(result.Fail(OperationResultHelper.ProcessResponseData(response.Data)));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Details(int id, bool showSuccessMessage = false)
        {
            var result = await _movieService.GetMovie(id);

            if (!result.IsSuccess)
            {
                return(RedirectToAction("Index", new { pageNumber = 1, isSuccess = result.IsSuccess }));
            }
            var movie = result.Data;

            var isCurrentUserDownloader = await _userManager.CheckEditPermissionAsync(User, movie);

            var model = MovieViewModel.FromModel(movie, isCurrentUserDownloader);

            if (showSuccessMessage)
            {
                model.Message          = OperationResultHelper.GetMessage(isSuccess: true);
                model.IsSuccessMessage = true;
            }
            return(View(model));
        }
        protected override IOperationResult ProcessResponse(BinaryResponse response)
        {
            var result = new BinaryOperationResult();
            var status = response.StatusCode;

            this.StatusCode = status;

            if (status == 0)
            {
                var data = response.Data;
                if (data.Count != 8)
                {
                    return(result.Fail("Result must be 8 bytes long, received: " + data.Count, new InvalidOperationException()));
                }

                this._result = BinaryConverter.DecodeUInt64(data.Array, data.Offset);
                return(result.Pass());
            }

            var message = OperationResultHelper.ProcessResponseData(response.Data);

            return(result.Fail(message));
        }