public PhotoGalleryAddOrUpdateResponseDto AddOrUpdate(PhotoGalleryAddOrUpdateRequestDto request) { var entity = _repository.GetAll() .FirstOrDefault(x => x.Id == request.Id && x.IsDeleted == false); if (entity == null) { _repository.Add(entity = new Models.PhotoGallery()); } entity.Name = request.Name; _uow.SaveChanges(); return(new PhotoGalleryAddOrUpdateResponseDto(entity)); }
public PhotoGalleryAddOrUpdateResponseDto AddOrUpdate(PhotoGalleryAddOrUpdateRequestDto request) { var entity = GetAll() .FirstOrDefault(x => x.Id == request.Id && x.IsDeleted == false); if (entity == null) { repository.Add(entity = new PhotoGallery()); } entity.Name = request.Name; entity.PhotoGalleryDigitalAssets.Clear(); foreach (var photo in request.Photos) { entity.PhotoGalleryDigitalAssets.Add(new PhotoGalleryDigitalAsset() { DigitalAsset = uow.DigitalAssets.GetById(photo.Id) }); } uow.SaveChanges(); return(new PhotoGalleryAddOrUpdateResponseDto(entity)); }
public IHttpActionResult Update(PhotoGalleryAddOrUpdateRequestDto dto) { return(Ok(_photoGalleryService.AddOrUpdate(dto))); }