Ejemplo n.º 1
0
        public Task HandleAsync(UpdateMediaCommand command)
        {
            var phoneId = Convert.ToInt32(_httpContextAccessor.HttpContext.Request.RouteValues["Id"]);

            var mediaResult = _mediaRepository
                              .GetAll()
                              .Where(m => m.PhoneId == phoneId);

            MediaValidator.Validate(mediaResult);

            int mediaResultIndex = 0;

            foreach (Media media in mediaResult)
            {
                for (int i = mediaResultIndex; i < mediaResult.Count();)
                {
                    media.Photo = command.Media[i].Photo;
                    media.Video = command.Media[i].Video;

                    _mediaRepository.Update(media);
                    mediaResultIndex++;

                    break;
                }
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        public Task <PhoneMediaResonse> HandleAsync(PhoneMediaQuery query)
        {
            var media = _mediaRepository
                        .GetAll()
                        .Where(m => m.PhoneId == query.Id);

            MediaValidator.Validate(media);

            return(Task.FromResult(new PhoneMediaResonse {
                Media = _mapper.Map <List <PhoneMediaViewModel> >(media)
            }));
        }
        public Task HandleAsync(DeleteMediaCommand command)
        {
            var phoneId = Convert.ToInt32(_httpContextAccessor.HttpContext.Request.RouteValues["Id"]);

            var medias = _mediaRepository
                         .GetAll()
                         .Where(m => m.PhoneId == phoneId);

            MediaValidator.Validate(medias);

            foreach (Media m in medias)
            {
                _mediaRepository.Delete(m);
            }

            return(Task.CompletedTask);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method to validate model
        /// </summary>
        /// <returns>Returns the result of validation</returns>
        protected override FluentValidation.Results.ValidationResult Validate()
        {
            var validator = new MediaValidator();

            return(validator.Validate(this));
        }