public async Task <IActionResult> Register(TenantEditViewModel tenantVm)
        {
            var loggedUser = await _authService.GetUserClaims(User);

            if (!ModelState.IsValid)
            {
                // re-render the view when validation failed.
                return(View("Register", tenantVm));
            }

            try
            {
                tenantVm.PropertyList = GetPropertyList();
                tenantVm.UnitList     = GetUnitListItems(tenantVm.SelectedPropertyCode);
                var propCode   = tenantVm.SelectedPropertyCode == _selectPropertyTip ? "" : tenantVm.SelectedPropertyCode;
                var unitNumber = (tenantVm.SelectedUnitNumber == null || tenantVm.SelectedUnitNumber.StartsWith("--"))
                    ? ""
                    : tenantVm.SelectedUnitNumber;



                await _propertyService.RegisterTenantAsync(propCode, tenantVm.ContactInfo, unitNumber);


                //return RedirectToAction("Requests", "Tenant");
                //TempData["JustEnrolled"] = "yes";
                //return base.RedirectToAction("SignOut", "Account", new { area = "AzureADB2C" });

                return(_redirectionService.RedirectAfterEnrollment(TempData, this));
            }

            catch (CoreAuthorizationException)
            {
                return(base.RedirectToAction(actionName: "AccessDenied", controllerName: "Home"));
            }
            catch (DomainEntityDuplicateException)
            {
                ModelState.AddModelError("SelectedUnitNumber", "The Unit is already taken");
                return(View("Register", tenantVm));
            }
            catch (DomainValidationException vex)
            {
                MapValidationErrorsToModel(vex);

                return(View(tenantVm));
            }
            catch (DomainException dex)
            {
                ModelState.AddModelError("", dex.Message);
                return(View("Register", tenantVm));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View("Register", tenantVm));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Register(WorkerEditViewModel worker)
        {
            if (!ModelState.IsValid)
            {
                // re-render the view when validation failed.
                return(View("Register", worker));
            }
            var loggedUser = await _authService.GetUserClaims(User);

            try
            {
                await _propertyService.RegisterWorkerAsync(worker.ContactInfo);
            }
            catch (CoreAuthorizationException)
            {
                return(base.RedirectToAction(actionName: "AccessDenied", controllerName: "Home"));
            }
            catch (DomainValidationException vex)
            {
                MapValidationErrorsToModel(vex);

                return(View(worker));
            }
            catch (DomainException dex)
            {
                ModelState.AddModelError("", dex.Message);
                return(View("Register", worker));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View("Register", worker));
            }

            //await _securityService.SetLoggedUserClaims( User.Identity.Name , UserRolesEnum.Worker ,"","");

            //return RedirectToAction("Requests", "Worker"); //, new { propCode = propCode, unit = unitNumber });
            return(_redirectionService.RedirectAfterEnrollment(TempData, this));
        }
        public async Task <IActionResult> Register(PropertyModel prop)
        {
            if (!ModelState.IsValid)
            {
                // re-render the view when validation failed.
                return(View("Register", prop));
            }

            var loggedUser = await _authService.GetUserClaims(User);

            prop.Units = new List <string>();

            if (!string.IsNullOrEmpty(prop.UnitsStr))
            {
                var arr = prop.UnitsStr.Split(',');
                prop.Units = arr.ToList().Select(x => string.IsNullOrEmpty(x) ? "" : x.Trim()).ToList();
            }

            try
            {
                await _propertyService.RegisterPropertyAsync(new RegisterPropertyCommand(prop.Name, prop.Code, prop.Address,
                                                                                         prop.PhoneNumber,
                                                                                         prop.Superintendent,
                                                                                         prop.Units.ToList(), prop.NoReplyEmailAddress));
            }
            catch (CoreAuthorizationException)
            {
                return(base.RedirectToAction(actionName: "AccessDenied", controllerName: "Home"));
            }
            catch (DomainValidationException vex)
            {
                ModelState.Clear();
                foreach (var err in vex.Errors)
                {
                    var propName = err.PropertyName.ToString();
                    if (propName.StartsWith("Units") && propName != "UnitsStr")
                    {
                        propName = "UnitsStr";
                    }
                    ModelState.AddModelError(propName, err.ErrorMessage);
                }

                return(View("Register", prop));
            }
            catch (DomainEntityDuplicateException)
            {
                ModelState.AddModelError("Code", "The code is already taken");
                return(View("Register", prop));
            }
            catch (DomainException dex)
            {
                ModelState.AddModelError("", dex.Message);
                return(View("Register", prop));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View("Register", prop));
            }


            //return RedirectToAction("Requests", "Superintendent");
            return(_redirectionService.RedirectAfterEnrollment(TempData, this));
        }