예제 #1
0
        public async Task Update(ProductPutModel putModel)
        {
            if (putModel == null)
            {
                throw new InvalidArgumentException($"{typeof(ProductPutModel).Name} was null!");
            }

            var item = await _readOnly.ExistsAsync <Product>(q => q.Id == putModel.Id);

            if (item == false)
            {
                throw new NotFoundException($"Can't find a {typeof(Product).Name} with ID = {putModel.Id}");
            }

            var entity = _mapper.Map <Product>(putModel);

            await _fileService.UploadImage(entity.Image);

            await _writeOnly.SaveChangesAsync(entity);

            if (entity.Image != null)
            {
                await _writeOnly.SaveChangesAsync(entity.Image);
            }
        }
예제 #2
0
        public async Task Update(CustomerPutModel putModel)
        {
            if (putModel == null)
            {
                throw new InvalidArgumentException($"{typeof(CustomerPutModel).Name} was null!");
            }

            var item = await _readOnly.ExistsAsync <Customer>(q => q.Id == putModel.Id);

            if (item == false)
            {
                throw new NotFoundException($"Can't find a {typeof(Customer).Name} with ID = {putModel.Id}");
            }

            var entity = _mapper.Map <Customer>(putModel);

            await _writeOnly.SaveChangesAsync(entity);
        }