Пример #1
0
        public async Task AddAsync(MyTask.BusinessLogic.Models.CarModels.Product product)
        {
            var entity = _mapper.Map <MyTask.DataAccess.Models.Models.Product>(product);

            using var context = _contextFactory;

            await context.Products.AddAsync(entity).ConfigureAwait(false);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
Пример #2
0
        public async Task <IActionResult> Put(MyTask.BusinessLogic.Models.CarModels.Product product)
        {
            try
            {
                if (product == null)
                {
                    return(BadRequest("product is required"));
                }

                await _productService.UpdateAsync(product);

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e));
            }
        }
Пример #3
0
        public async Task UpdateAsync(MyTask.BusinessLogic.Models.CarModels.Product product)
        {
            var context = _contextFactory;

            var entity = await context.Products.FirstOrDefaultAsync(item => item.Id.Equals(product.Id))
                         .ConfigureAwait(false);

            if (entity == null)
            {
                return;
            }

            entity.Name  = product.Name;
            entity.Price = product.Price;


            context.Products.Update(entity);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }