Пример #1
0
        public async Task <IActionResult> AddImage(CustomerImageViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var path = string.Empty;

                if (viewModel.ImageFile != null)
                {
                    path = await _imageHelper.UploadCustomerImageAsync(viewModel.ImageFile);
                }

                var customerImage = new CustomerImage
                {
                    ImageUrl = path,
                    Customer = await _dataContext.Customers.FindAsync(viewModel.Id)
                };

                _dataContext.CustomerImages.Add(customerImage);
                await _dataContext.SaveChangesAsync();

                return(RedirectToAction("Details", "Customers", new { id = viewModel.Id }));
            }

            return(View(viewModel));
        }
Пример #2
0
        public async Task <IActionResult> AddImage(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var customer = await _dataContext.Customers.FindAsync(id.Value);

            if (customer == null)
            {
                return(NotFound());
            }

            var model = new CustomerImageViewModel
            {
                Id = customer.Id
            };

            return(View(model));
        }