Пример #1
0
        public async Task UpdateRecipe(CreateRecipeViewModel model, IPrincipal user)
        {
            var unitOfWork = OwinContext.Get <UnitOfWork>();

            // retrieve model from database
            var recipe = await unitOfWork.Recipes.GetById(model.Id);

            if (recipe == null)
            {
                throw new ObjectNotFoundException("The entry you are looking for doesn't exist in our database.");
            }

            // update model
            recipe.Title       = model.Title;
            recipe.Description = model.Description;
            if (model.PictureFile != null)
            {
                var fileStorageService = new LocalFileStorageService();
                var picturePath        = fileStorageService.StoreFile(model.PictureFile);
                model.Picture = picturePath;
            }

            // save changes of modified model
            await unitOfWork.SaveChangesAsync();
        }
Пример #2
0
        /// <summary>
        /// Configures file storage service.
        /// </summary>
        public static void ConfigureStorage(this IServiceCollection services, IConfiguration configuration, ILogger logger)
        {
            var storageService = new LocalFileStorageService(configuration["LocalFileStorageBasePath"]);

            services.AddSingleton <IFileStorageService>(storageService);

            logger.LogInformation("Configured Storage service.");
        }
Пример #3
0
        public async Task <long> SaveAsync(Stream stream, string contentType)
        {
            var fileName = await LocalFileStorageService.SaveAsync(stream);

            var metadata = new FileMetadata
            {
                ContentType = contentType.ToLower(),
                Size        = (int)stream.Length,
                Filename    = fileName
            };
            await metadata.GenerateIdAsync(IdentityGenerator);

            await FileMetadataRepository.SaveAsync(metadata);

            return(metadata.Id);
        }
Пример #4
0
        public async Task CreateNewRecipe(CreateRecipeViewModel model, IPrincipal user)
        {
            var fileStorageService = new LocalFileStorageService();
            var picturePath        = fileStorageService.StoreFile(model.PictureFile);

            // create model
            var recipe = new Recipe()
            {
                Title       = model.Title,
                Description = model.Description,
                Picture     = picturePath,
                AuthorId    = user.Identity.GetUserId()
            };

            // insert model in the database
            await UnitOfWork.Recipes.Add(recipe);

            // save changes
            await UnitOfWork.SaveChangesAsync();
        }
Пример #5
0
        public async Task UpdateRecipe(CreateRecipeViewModel model, IPrincipal user)
        {
            // retrieve model from database
            var recipe = await UnitOfWork.Recipes.GetById(model.Id);

            if (recipe == null)
            {
                throw new EntityNotFoundException <Recipe, int>(model.Id, typeof(Recipe));
            }

            // update model
            recipe.Title       = model.Title;
            recipe.Description = model.Description;
            if (model.PictureFile != null)
            {
                var fileStorageService = new LocalFileStorageService();
                var picturePath        = fileStorageService.StoreFile(model.PictureFile);
                recipe.Picture = picturePath;
            }

            // save changes of modified model
            await UnitOfWork.SaveChangesAsync();
        }
 public LocalFileStorageServiceTest()
 {
     _localFileStorageService = new LocalFileStorageService(_basePath);
 }
Пример #7
0
        public static void ConfigureStorage(this IServiceCollection services, IConfiguration configuration)
        {
            var storageService = new LocalFileStorageService(configuration ["LocalFileStorageBasePath"]);

            services.AddSingleton <IFileStorageService> (storageService);
        }