Exemple #1
0
        public async Task <IActionResult> Edit(AssistantViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var path = model.ImageUrl;

                    if (model.ImageFile != null && model.ImageFile.Length > 0)
                    {
                        path = await _imageHelper.UploadImageAsync(model.ImageFile, "Assistants");
                    }


                    var assistant = _converterHelper.ToAssistant(model, path, false);

                    assistant.ModifiedBy = await _userHelper.GetUserByEmailAsync(User.Identity.Name);

                    await _assistantRepository.UpdateAsync(assistant);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await _assistantRepository.ExistAsync(model.Id))
                    {
                        return(new NotFoundViewResult("AssistantNotFound"));
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }