public async Task <GearImageViewModel> AddGearImageAsync(GearImageViewModel gearImageViewModel, CancellationToken ct = default)
        {
            GearImage newGearImage = new GearImage()
            {
                GearItemId         = gearImageViewModel.GearItemId,
                CloudinaryPublicId = gearImageViewModel.CloudinaryPublicId,
                Name         = gearImageViewModel.Name,
                Size         = gearImageViewModel.Size,
                Type         = gearImageViewModel.Type,
                Url          = gearImageViewModel.Url,
                Small        = gearImageViewModel.Small,
                Medium       = gearImageViewModel.Medium,
                Big          = gearImageViewModel.Big,
                ResourceType = gearImageViewModel.ResourceType,
                Width        = gearImageViewModel.Width,
                Height       = gearImageViewModel.Height,
                Format       = gearImageViewModel.Format,
            };

            newGearImage = await _gearImageRepository.AddAsync(newGearImage, ct);

            gearImageViewModel.Id = newGearImage.Id;

            return(gearImageViewModel);
        }
Ejemplo n.º 2
0
        public async Task <GearImage> AddAsync(GearImage gearSize, CancellationToken ct = default)
        {
            _dbContext.GearImages.Add(gearSize);
            await _dbContext.SaveChangesAsync(ct);

            return(gearSize);
        }
Ejemplo n.º 3
0
        public async Task <bool> DeleteAsync(long?id, CancellationToken ct = default)
        {
            if (!await GearImageExists(id, ct))
            {
                return(false);
            }

            GearImage gearImageToDelete = this._dbContext.GearImages.Find(id);

            _dbContext.GearImages.Remove(gearImageToDelete);
            await _dbContext.SaveChangesAsync(ct);

            return(true);
        }
        public async Task <bool> UpdateGearItemAsync(GearItemViewModel gearItemViewModel, CancellationToken ct = default)
        {
            GearItem gearItem = await _gearItemRepository.GetByIDAsync(gearItemViewModel.Id, ct);

            if (gearItem == null)
            {
                return(false);
            }

            gearItem.Name    = gearItemViewModel.Name;
            gearItem.InStock = gearItemViewModel.InStock;
            gearItem.Price   = gearItemViewModel.Price;

            // If incoming gearItemViewModel image count is smaller than existing, this means we are removing images
            if (gearItemViewModel.Images.Count() < gearItem.Images.Count())
            {
                IList <GearImage> deleteGearImages = gearItem.Images.Where(existingGearImage => !gearItemViewModel.Images.Any(updatedGearImage => updatedGearImage.Id == existingGearImage.Id)).ToList();

                // Delete all images marked for deletion
                int length = deleteGearImages.Count();
                for (int i = 0; i < length; i++)
                {
                    GearImage gearImage = deleteGearImages.ElementAt(i);
                    await this._gearImageRepository.DeleteAsync(gearImage.Id, ct);
                }
            }

            // Check if we are adding any newImages. If we arent this means the gearItem will have NO default image
            if (gearItemViewModel.NewImages != null)
            {
                // Add all new incoming images
                foreach (GearImageViewModel gearImage in gearItemViewModel.NewImages)
                {
                    gearImage.GearItemId = gearItem.Id;
                    await this.AddGearImageAsync(gearImage, ct);
                }
            }

            // Update incoming sizes
            foreach (GearSizeViewModel gearSize in gearItemViewModel.Sizes)
            {
                await this.UpdateGearSizeAsync(gearSize, ct);
            }

            return(await this._gearItemRepository.UpdateAsync(gearItem));
        }
Ejemplo n.º 5
0
        public static GearImageViewModel Convert(GearImage gearImage)
        {
            GearImageViewModel gearImageViewModel = new GearImageViewModel();

            gearImageViewModel.Big                = gearImage.Big;
            gearImageViewModel.Id                 = gearImage.Id;
            gearImageViewModel.Medium             = gearImage.Medium;
            gearImageViewModel.Name               = gearImage.Name;
            gearImageViewModel.Size               = gearImage.Size;
            gearImageViewModel.Small              = gearImage.Small;
            gearImageViewModel.Type               = gearImage.Type;
            gearImageViewModel.Url                = gearImage.Url;
            gearImageViewModel.CloudinaryPublicId = gearImage.CloudinaryPublicId;
            gearImageViewModel.Height             = gearImage.Height;
            gearImageViewModel.Width              = gearImage.Width;
            gearImageViewModel.ResourceType       = gearImage.ResourceType;
            gearImageViewModel.Format             = gearImage.Format;

            return(gearImageViewModel);
        }
Ejemplo n.º 6
0
 public Task <bool> UpdateAsync(GearImage gearSize, CancellationToken ct = default)
 {
     throw new System.NotImplementedException();
 }