Beispiel #1
0
        public async Task <IActionResult> EditImage(IndexViewData data)
        {
            var fileUploadResponse = new DefaultServiceResponse();

            var viewModel = new IndexViewData();

            if (data.FormFileData != null)
            {
                var customerData = await UserManager.GetUserAsync(User);

                if (customerData != null)
                {
                    fileUploadResponse = await FileManagerService.LoadFileToTheServer(data.FormFileData, customerData.Id);
                }

                if (fileUploadResponse.ValidationErrors != null)
                {
                    foreach (var error in fileUploadResponse.ValidationErrors)
                    {
                        ModelState.AddModelError("", error);
                    }
                }

                viewModel.PathToTheInputImage = Path.Combine("../", "CustomersImages",
                                                             Path.GetFileName(fileUploadResponse.ResponseData.ToString()));

                Logger.LogInformation($"Path to the input image, uploaded by the customer - {viewModel.PathToTheInputImage}");
            }
            else
            {
                ModelState.AddModelError("", "In order to edit photo, you should first provide it");
            }

            return(View(viewModel));
        }