Ejemplo n.º 1
0
        public async Task <IActionResult> Create(CompanyUnitViewModel companyUnitViewModel)
        {
            companyUnitViewModel.Companies = await this.GetAllCompaniesList();

            if (!ModelState.IsValid)
            {
                return(View(companyUnitViewModel));
            }

            var companyUnit = _mapper.Map <CompanyUnit>(companyUnitViewModel);
            await _companyUnitService.Add(companyUnit);

            if (!IsValidOperation())
            {
                return(View(companyUnitViewModel));
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(Guid id, CompanyUnitViewModel companyUnitViewModel)
        {
            if (id != companyUnitViewModel.Id)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                companyUnitViewModel.Companies = _mapper.Map <IEnumerable <CompanyViewModel> >(await _companyRepository.GetAll());
                return(View(companyUnitViewModel));
            }

            var companyUnit = _mapper.Map <CompanyUnit>(companyUnitViewModel);
            await _companyUnitService.Update(companyUnit);

            if (!IsValidOperation())
            {
                return(View(companyUnitViewModel));
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 3
0
        private async Task <CompanyUnitViewModel> GetCompanies(CompanyUnitViewModel companyUnitViewModel)
        {
            companyUnitViewModel.Companies = _mapper.Map <IEnumerable <CompanyViewModel> >(await _companyRepository.GetAll());

            return(companyUnitViewModel);
        }