예제 #1
0
        public async Task <IActionResult> Create(AssistantViewModel model)
        {
            if (ModelState.IsValid)
            {
                var path = string.Empty;

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

                try
                {
                    var assistant = _converterHelper.ToAssistant(model, path, true);

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

                    await _assistantRepository.CreateAsync(assistant);

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError(string.Empty, exception.Message);
                }
            }
            return(View(model));
        }