コード例 #1
0
ファイル: AdminService.cs プロジェクト: EldarMamishev/ITT
        public async Task EditCathedra(EditCathedraAdminView viewModel)
        {
            Company cathedra = await _companyRepository.Get(viewModel.Id);

            if (cathedra is null)
            {
                throw new AdminException("Entered cathedra doesn't exist.");
            }

            var changeCiphers = false;

            if (!(cathedra.Name.ToUpper().Equals(viewModel.Name.ToUpper())))
            {
                cathedra = await _companyRepository.FindCompanyByName(viewModel.Name);

                if (!(cathedra is null))
                {
                    throw new AdminException("Entered cathedra already exist.");
                }
            }

            _cathedraMapper.MapCathedraEditViewModelToCathedraModel(cathedra, viewModel);

            await _companyRepository.Update(cathedra);
        }
コード例 #2
0
        public async Task <IActionResult> EditCathedra(EditCathedraAdminView viewModel)
        {
            try
            {
                await _adminService.EditCathedra(viewModel);

                return(RedirectToAction("ShowCathedras"));
            }
            catch (AdminException ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);

                EditCathedraDataAdminView result = await _adminService.EditCathedra(viewModel.Id);

                return(View("Cathedras/EditCathedra", result));
            }
        }
コード例 #3
0
 public void MapCathedraEditViewModelToCathedraModel(Company model, EditCathedraAdminView viewModel)
 {
     model.Id   = viewModel.Id;
     model.Name = viewModel.Name;
 }