public async Task Add(string correlationToken, Product product)
        {
            // Idempotent write check. Ensure insert with same correlation token has
            // not already happened. This would most likely do to a retry after the
            // product has been added.
            var targetAlbum = await _musicRepository.GetByIdWithIdempotencyCheck(product.Id, correlationToken);

            if (targetAlbum == null)
            {
                // Product has not been added yet
                await _musicRepository.Add(product);

                // Hack: Yet another transformation of same data.
                //       Added to remove issue in new Core Serializer which doesn't allow circular references.
                var productUpsert = new ProductUpsert
                {
                    Id              = product.Id,
                    ArtistId        = product.ArtistId,
                    GenreId         = product.GenreId,
                    Title           = product.Title,
                    ParentalCaution = product.ParentalCaution,
                    Cutout          = product.Cutout,
                    Price           = product.Price,
                    ReleaseDate     = product.ReleaseDate,
                    Upc             = product.Upc
                };
                await _eventBusPublisher.Publish <ProductChangedEvent>(
                    await PrepareProductChangedEvent(productUpsert, correlationToken));
            }
        }
예제 #2
0
        public async Task <Product> Add(string correlationToken, Product product)
        {
            // Idempotent write check. Ensure insert with same correlation token has
            // not already happened. This would most likely do to a retry after the
            // product has been added.
            var targetAlbum = await _musicRepository.GetByIdWithIdempotencyCheck(product.Id, correlationToken);

            if (targetAlbum == null)
            {
                // Product has not been added yet
                await _musicRepository.Add(product);
            }
            else
            {
                // Assign Id from original insert
                product.Id = targetAlbum.Id;
            }

            //************** Publish Event  *************************
            // Publish event that informs application that product has changed
            //   First Argument: Event Data object
            //   Second Argument: EventType Enum
            //   Third Argrment: Correalation Token
            await _eventBus.Publish(await PrepareProductChangedEvent(product, correlationToken),
                                    MessageEventEnum.ProductChangedEvent,
                                    correlationToken);

            return(product);
        }
예제 #3
0
        public void AddSong(string songTitle, TimeSpan songDuration, Album album)
        {
            if (album == null)
            {
                return;
            }

            Song song = new Song
            {
                Duration = songDuration,
                Album    = album,
                Title    = songTitle
            };

            _albumSongs[album.Id].Add(_musicRepository.Add(song));

            Changed();
        }
 public ActionResult Create(Music model)
 {
     try
     {
         var x = _musicRepository.Add(model);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
예제 #5
0
        public ActionResult AddInstrument(Instrument instrument)
        {
            if (_dashboardSP.CheckDuplicate <Instrument>(instrument.InstrumentName, instrument.Website))
            {
                TempData["CustomError"] = "Instrument ( " + instrument.InstrumentName + " ) already exists!";
                ModelState.AddModelError("CustomError", "Instrument ( " + instrument.InstrumentName + " ) already exists!");
            }

            if (ModelState.IsValid)
            {
                _dashboardSP.Add(instrument);

                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("AddInstrument"));
        }
예제 #6
0
        public ActionResult Add(MusicModel music)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View("AddMusic", music));
                }
                var model = new Music();
                model.Song_Id   = music.Song_Id;
                model.Name_Song = music.Name_Song;
                model.Singer    = music.Singer;
                model.Time      = music.Time;
                musicRepository.Add(model);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }