Ejemplo n.º 1
0
        public IActionResult Update(OrganizationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Countries = _countryManager.GetCountries().Select(c => new SelectListItem {
                    Text = c.Name, Value = c.IsoCountryCode
                }).ToList();
                return(View(nameof(Update), model));
            }

            var user = _userManager.GetUserAsync(User).Result;

            if (model.Id.HasValue && !_companyManager.IsUserCompanyAdmin(user.Id, model.Id.Value))
            {
                return(NotFound());
            }

            try
            {
                var company = model.ToBusinessObject <CompanyBo>();
                _companyManager.Update(company);

                return(RedirectToAction(nameof(Update), model.Id));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                return(View(nameof(Update), model));
            }
        }