public DataSourceResult Save(PicturesModel viewModel, ModelStateDictionary modelState)
        {
            if (viewModel != null && modelState.IsValid)
            {
                var repo = this.RepoFactory.Get <PictureRepository>();

                MemoryStream target = null;

                if (viewModel.Files != null)
                {
                    foreach (var file in viewModel.Files)
                    {
                        int fileSizeInBytes = file.ContentLength;
                        target = new MemoryStream();
                        file.InputStream.CopyTo(target);

                        var entity = new Picture
                        {
                            BlindTypeId      = viewModel.BlindTypeId,
                            OriginalFileName = file.FileName,
                            Extension        = file.ContentType,
                            OriginalSize     = file.ContentLength,
                            Content          = target.ToArray()
                        };

                        repo.Add(entity);
                    }
                }

                try
                {
                    repo.SaveChanges();
                    viewModel.Id    = 0;
                    viewModel.Files = null;
                    return(null);
                }
                catch (DbEntityValidationException e)
                {
                    return(new DataSourceResult
                    {
                        Errors = this.HandleDbEntityValidationException(e)
                    });
                }
            }
            else
            {
                return(this.HandleErrors(modelState));
            }
        }
        public DataSourceResult Destroy(PicturesModel viewModel, ModelStateDictionary modelState)
        {
            if (viewModel != null && modelState.IsValid)
            {
                var repo   = this.RepoFactory.Get <PictureRepository>();
                var entity = repo.GetById(viewModel.Id);

                entity.Deleted   = true;
                entity.DeletedOn = DateTime.Now;

                repo.SaveChanges();
                return(null);
            }
            else
            {
                return(this.HandleErrors(modelState));
            }
        }