Ejemplo n.º 1
0
        public string Register([FromBody] RegistrationViewModel registrationViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var user          = _userDomainService.CreateUser(registrationViewModel);
                    var userInfoModel = _userDomainService.GetUserInfoViewModel(registrationViewModel.Login, registrationViewModel.Password);
                    return(JsonConvert.SerializeObject(this._getAuthorizationType(userInfoModel),
                                                       new JsonSerializerSettings {
                        Formatting = Formatting.Indented
                    }));
                }
                else
                {
                    List <ValidationViewModel> validationSummary = new List <ValidationViewModel>();

                    foreach (var field in ModelState.Keys)
                    {
                        var erorMessages = ModelState[field].Errors.Select(a => a.ErrorMessage);
                        validationSummary.Add(new ValidationViewModel
                        {
                            ErrorsMessages = erorMessages.ToList(),
                            FieldName      = field
                        });
                    }

                    return(this._getAuthorizationTypeError(validationSummary: validationSummary));
                }
            }
            catch (Exception ex)
            {
                return(this._getAuthorizationTypeError(ex.Message));
            }
        }