コード例 #1
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            PropertyInfo property = validationContext.ObjectType.GetProperty(this.ImageCollectinFieldName);

            if (property == null)
            {
                throw new Exception(this.GetExceptionMessage(validationContext));
            }
            object obj = property.GetValue(validationContext.ObjectInstance, null);

            if (obj == null)
            {
                throw new Exception(this.GetExceptionMessage(validationContext));
            }
            ImageListVm imageList = obj as ImageListVm;

            if (imageList == null)
            {
                throw new Exception(this.GetExceptionMessage(validationContext));
            }
            if (base.CheckCollectionOnValidLength(imageList.Images))
            {
                return(ValidationResult.Success);
            }
            return(new ValidationResult(base.ErrorMessage));
        }
コード例 #2
0
        public ActionResult ImageList(int restaurantId)
        {
            var model  = new ImageListVm();
            var images = service.Uow.RestaurantImages.GetByRestaurantId(restaurantId);

            if (images.Count > 0)
            {
                model.RestaurantImages = new List <RestaurantImage>();
                model.RestaurantImages.AddRange(images);
            }
            model.RestaurantId = restaurantId;
            return(PartialView(model));
        }