Example #1
0
        public async Task UpdateAsync(PosterInputDTO posterDto)
        {
            await TryCatch(async() =>
            {
                var poster = await _repository.FindAsync(posterDto.Id);

                poster.PetName          = posterDto.PetName;
                poster.PetType          = (EPetType)posterDto.PetType;
                poster.Castrated        = posterDto.Castrated;
                poster.Dewormed         = posterDto.Dewormed;
                poster.DeliverToAdopter = false;
                poster.Country          = posterDto.Country;
                poster.State            = posterDto.State;
                poster.City             = posterDto.City;
                poster.IsAdopted        = posterDto.IsAdopted;

                await _repository.UpdateAsync(poster);

                foreach (var p in poster.PetPictures)
                {
                    await _blobService.DeleteBlobStorageAsync(p.Url);
                }

                await _petPictureService.DeleteMany(poster.Id);

                foreach (var pic in posterDto.PetPictures)
                {
                    await _petPictureService.Create(pic, poster.Id);
                }
            });
        }
Example #2
0
        public async Task <Poster> CreateAsync(PosterInputDTO posterDto)
        {
            return(await TryCatch(async() =>
            {
                var poster = new Poster
                {
                    UserId = posterDto.UserId,
                    PetName = posterDto.PetName,
                    PetType = (EPetType)posterDto.PetType,
                    Castrated = posterDto.Castrated,
                    Dewormed = posterDto.Dewormed,
                    DeliverToAdopter = posterDto.DeliverToAdopter,
                    Country = posterDto.Country,
                    State = posterDto.State,
                    City = posterDto.City,
                    IsAdopted = posterDto.IsAdopted
                };

                poster = await _repository.CreateAsync(poster);

                foreach (var pic in posterDto.PetPictures)
                {
                    await _petPictureService.Create(pic, poster.Id);
                }

                return poster;
            }));
        }
        public async Task <IHttpActionResult> Put(PosterInputDTO model)
        {
            await _posterService.UpdateAsync(model).ConfigureAwait(false);

            return(Ok());
        }
        public async Task <IHttpActionResult> Post(PosterInputDTO model)
        {
            var poster = await _posterService.CreateAsync(model).ConfigureAwait(false);

            return(Ok(MappingConfig.Mapper().Map <PosterOutputDTO>(poster)));
        }