Exemplo n.º 1
0
        public async Task <int> Create(
            string name,
            string description,
            decimal price,
            string userId,
            string[] images)
        {
            var advertisement = new Advertisement
            {
                Name        = name,
                Description = description,
                Price       = price,
                UserId      = userId,
                CategoryId  = 1,
            };

            await _db.AddAsync(advertisement);

            await _db.SaveChangesAsync();

            await _db.AddRangeAsync(images
                                    .Select(i => new AdvertisementImage
            {
                AdvertisementId  = advertisement.Id,
                ImageString      = i,
                SmallImageString = _imageSizeReducer.GetReducedSizeImage(i, 150, 150),
            }));

            await _db.SaveChangesAsync();

            return(advertisement.Id);
        }