コード例 #1
0
        public async Task <IActionResult> PutCustomerModel(int id, CustomerModel customerModel)
        {
            if (id != customerModel.CustomerId)
            {
                return(BadRequest());
            }

            if (customerModel.ImageData != null)
            {
                _iimageService.DeleteImage(customerModel.CustomerImage);
                customerModel.CustomerImage = await _iimageService.SaveImage(customerModel.ImageData);
            }
            _context.Entry(customerModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> UpdateProduts(int id, [FromForm] ProductModel newProduct)
        {
            if (id != newProduct.ProductId)
            {
                return(BadRequest());
            }

            if (newProduct.ImageData != null)
            {
                _iimageService.DeleteImage(newProduct.Image);
                newProduct.Image = await _iimageService.SaveImage(newProduct.ImageData);
            }

            _db.Entry(newProduct).State = EntityState.Modified;

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException error)
            {
                throw error;
            }

            return(NoContent());
        }
コード例 #3
0
        public async Task <ActionResult <CustomerModel> > DeleteUserCustomer(int id)
        {
            var customerModel = await _context.CustomerModels.FindAsync(id);

            if (customerModel == null)
            {
                return(BadRequest());
            }
            _context.CustomerModels.Remove(customerModel);
            await _context.SaveChangesAsync();

            return(customerModel);
        }
コード例 #4
0
        public async Task <ActionResult <ProductModel> > AddProducts([FromBody] ProductModel newProduct)
        {
            try
            {
                Console.WriteLine("dddddddddddddddddddd");
                newProduct.Image = await _iimageService.SaveImage(newProduct.ImageData);

                _db.ProductModels.Add(newProduct);
                await _db.SaveChangesAsync();

                return(newProduct);
            }
            catch (Exception ex) {
                Console.WriteLine("dddddddddddddddddddd");

                throw ex;
            }
        }