Ejemplo n.º 1
0
        public override CommandResult Handle(AddMasterProductCommand command)
        {
            if (IsValid(command))
            {
                var photos = new List <Photo>();

                foreach (var item in command.Photos)
                {
                    photos.Add(new Photo()
                    {
                        Url = item
                    });
                }


                MasterProduct masterProduct = new MasterProduct
                {
                    Name             = command.Name,
                    Price            = command.Price,
                    Discount         = command.Discount,
                    Description      = command.Description,
                    ShortDescription = command.ShortDescription,
                    MasterId         = command.MasterId,
                    CategoryId       = command.CategoryId,
                    Photos           = photos
                };
                _commandRepository.Add(masterProduct);
                return(Ok());
            }
            return(Failure());
        }
 public override CommandResult Handle(AddMasterProductCommand command)
 {
     if (IsValid(command))
     {
         var masterProductPhotoCollection = new List <MasterProductPhoto>();
         foreach (var photoUrlSize in command.DtoPhotoUrlSizes)
         {
             masterProductPhotoCollection.Add(new MasterProductPhoto {
                 Photo = new Photo {
                     Url = photoUrlSize.PhotoUrl, Size = photoUrlSize.PhotoSize
                 }
             });
         }
         MasterProduct masterProduct = new MasterProduct
         {
             MasterId            = command.MasterId,
             CategoryId          = command.CategoryId,
             Name                = command.Name,
             Price               = command.Price,
             Discount            = command.Discount,
             Description         = command.Description,
             ShortDescription    = command.ShortDescription,
             masterProductPhotos = masterProductPhotoCollection,
             MainPhoto           = new Photo {
                 Url = command.MainPhotoUrlSize.PhotoUrl, Size = command.MainPhotoUrlSize.PhotoSize
             }
         };
         _commandRepository.Add(masterProduct);
         return(Ok());
     }
     return(Failure());
 }