Beispiel #1
0
 public UserException(string userError, int code = 400) : this(code)
 {
     if (!string.IsNullOrWhiteSpace(userError))
     {
         UserErrors.Add(userError);
     }
 }
Beispiel #2
0
 public UserException(string[] userErrors, int code = 400) : this(code)
 {
     if (userErrors != null && userErrors.Length != 0)
     {
         UserErrors.AddRange(userErrors);
     }
 }
        public void OnCompleteRender()
        {
            if (_spriteRenderer == null)
            {
                _spriteRenderer = new SpriteRenderer(_dxDeviceContext.Device, 128);
            }

            if (_redDotTexture == null)
            {
                String spritePath = System.IO.Path.Combine(Directories.GetResourceDirectory(), "LaserDot.png");

                if (!System.IO.File.Exists(spritePath))
                {
                    UserErrors.BadInstallation("resource", true);
                }

                _redDotTexture
                    = new ShaderResourceView(_dxDeviceContext.Device,
                                             Texture2D.FromFile(_dxDeviceContext.Device, spritePath));
            }

            if (ShowRedDot)
            {
                _spriteRenderer.Draw(_redDotTexture, new Vector2(10, 10), new Vector2(10, 10), CoordinateType.Absolute);
                _spriteRenderer.Flush();
            }

            _dxDeviceContext.SwapChain.Present(0, PresentFlags.None);
        }
Beispiel #4
0
 public UserException(List <string> userErrors, int code = 400) : this(code)
 {
     if (userErrors != null && userErrors.Count != 0)
     {
         UserErrors.AddRange(userErrors);
     }
 }
Beispiel #5
0
        public DefaultStyleAspect()
        {
            // No selection by default.
            SelectedObject = null;

            // Loading required style for unselected objects.
            try
            { _unSelected = StyleManager.CreateByName(SettingsManager.GetRef().RenderSettings.StyleName); }
            catch (Exception)
            {
                UserErrors.SettingsFileCorrupted("using default style");
                SettingsManager.GetRef().RenderSettings.StyleName = StyleManager.DefaultName;
                _unSelected = StyleManager.CreateByName(StyleManager.DefaultName);
            }

            // Creating style for selected objects.
            _selected = _unSelected.Clone() as StyleCollection;
            Material selectedMat = new Material(new SlimDX.Vector4(0.9f, 0.1f, 0.1f, 1.0f),
                                                new SlimDX.Vector4(0.0f, 0.0f, 0.0f, 1.0f),
                                                new SlimDX.Vector4(0.05f, 0.05f, 0.05f, 1.0f));

            foreach (var style in _selected.AllStyles)
            {
                style.SetProperties(selectedMat);
            }
        }
Beispiel #6
0
        public static StyleCollection CreateByName(String styleName)
        {
            StyleCollection res       = new StyleCollection();
            String          styleDir  = Directories.GetConfigDirectory();
            String          styleFile = System.IO.Path.Combine(styleDir, styleName);

            if (styleName.ToLower() == DefaultName.ToLower())
            {
                res.SetDefault();
                return(res);
            }
            else if (System.IO.File.Exists(styleFile))
            {
                try
                {
                    LoadStyleCollection(res, styleFile);
                }
                catch (Exception)
                {
                    UserErrors.ConfigFileCorrupted(styleName, "using default style");
                    res.SetDefault();
                }

                return(res);
            }
            else
            {
                throw new ApplicationException("Internal error - cannot find style file");
            }
        }
Beispiel #7
0
        /// <summary>
        /// Validates the resource owner password credential.
        /// </summary>
        /// <param name="context">The context</param>
        /// <returns>A task instance</returns>
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            var validationMonad = _userService
                                  .Validate(context.UserName, context.Password);

            var claimsMonad = validationMonad
                              .Bind(_userService.GetClaims);

            switch (claimsMonad)
            {
            case Success <IEnumerable <Claim>, Error> claims:
                var user = (validationMonad as Success <User, Error>) !.Value;
                context.Result = new GrantValidationResult(user.Id.ToString(),
                                                           OidcConstants.AuthenticationMethods.Password,
                                                           _clock.UtcNow.UtcDateTime,
                                                           claims: claims.Value);
                break;

            case Failure <IEnumerable <Claim>, Error> _:
                var error = UserErrors.UserPasswordDidNotMatch();
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, error.Message);
                break;

            default:
                break;
            }

            return(Task.CompletedTask);
        }
Beispiel #8
0
 public UserException(ModelStateDictionary modelState, int code = 400) : this(code)
 {
     UserErrors.AddRange(modelState
                         .Select(x => x.Value.Errors)
                         .Where(y => y.Count > 0)
                         .SelectMany(z => z)
                         .Select(e => e.ErrorMessage));
 }
Beispiel #9
0
        public async Task ResolveError(Guid id, string result, Dictionary <string, object> data)
        {
            var error = UserErrors.FindOrThrow(id);
            var ue    = (UserError)error.UserError;

            if ((data != null) && (ue.ContextInfo != null))
            {
                data.ForEach(x => ue.ContextInfo[x.Key] = x.Value);
            }
            ue.RecoveryOptions.First(x => x.CommandName == result).Execute(null);
            UserErrors = UserErrors.Except(new[] { error }).ToArray();
            await new UserErrorResolved(id, result).Raise().ConfigureAwait(false);
        }
Beispiel #10
0
        /// <summary>
        /// This method returns a User instance if the provided id belongs to one.
        /// </summary>
        /// <param name="id">The id of the user</param>
        /// <returns>An either monad of a User instance or an Error instance</returns>
        public Either <User, Error> Get(long id)
        {
            try
            {
                _logger.LogInformation($"New user request with id: {id}");

                var user = _burstChatContext
                           .Users
                           .FirstOrDefault(u => u.Id == id);

                return(user is { }
                    ? new Success <User, Error>(user)
                    : new Failure <User, Error>(UserErrors.UserNotFound()));
            }
        public ActionResult Login(UserErrors userModel)
        {
            if (!ModelState.IsValid)     //Checks if input fields have the correct format
            {
                return(View(userModel)); //Returns the view with the input values so that the user doesn't have to retype again
            }
            using (ResourcingToolConnection db = new ResourcingToolConnection())
            {
                // hash the password and compare against database
                if (!(userModel.UserName == null || userModel.Password == null))
                {
                    var hashedPassword = Sha256encrypt(userModel.Password);
                    var userDetails    = db.Users.Where(x => x.UserName == userModel.UserName && x.Password == hashedPassword).FirstOrDefault();

                    if (userDetails != null)
                    {
                        var identity = new ClaimsIdentity(new[] {
                            new Claim(ClaimTypes.Role, userDetails.Role),
                            new Claim(ClaimTypes.Name, userDetails.Name),
                            new Claim(ClaimTypes.NameIdentifier, userDetails.Id.ToString())
                        },
                                                          "ApplicationCookie");

                        // get owin context
                        var ctx = Request.GetOwinContext();
                        // get authentication manager
                        var authManager = ctx.Authentication;
                        //sign in as claimed identity- in this case the admin
                        //A user is authenticated by calling AuthenticationManager.SignIn
                        authManager.SignIn(identity);


                        //User is authenticated and redirected
                        return(RedirectToAction("Index", "Projects"));
                    }
                    else
                    {
                        userModel.ErrorMessage = "The username or password entered is incorrect. Please try again.";
                        //User authentication failed
                    }
                }
                else
                {
                    userModel.ErrorMessage = "The username or password entered is incorrect. Please try again.";
                    //User authentication failed - blank
                }
            }
            return(View(userModel)); //Should always be declared on the end of an action method
        }
Beispiel #12
0
        private UserErrors SaveUserInternal(User pUser)
        {
            var userErrors = new UserErrors();

            using (var connection = _userManager.GetConnection())
                using (var transaction = connection.BeginTransaction())
                {
                    try
                    {
                        if (pUser.Id == 0)
                        {
                            _userManager.AddUser(pUser, transaction);
                            if (_users != null)
                            {
                                _users.Add(pUser);
                            }
                            UserInterceptorSave(new Dictionary <string, object>
                            {
                                { "User", pUser },
                                { "SqlTransaction", transaction }
                            });
                            userErrors.ResultMessage = MultiLanguageStrings.GetString(Ressource.StringRes, "User_Save_OK.Text");
                        }
                        else
                        {
                            _userManager.UpdateUser(pUser, transaction);
                            UserInterceptorUpdate(new Dictionary <string, object>
                            {
                                { "User", pUser },
                                { "SqlTransaction", transaction }
                            });
                            userErrors.ResultMessage = MultiLanguageStrings.GetString(Ressource.StringRes, "User_Update_OK.Text");
                        }

                        transaction.Commit();
                        return(userErrors);
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                //var user1 = new ApplicationUser { UserName = model.Email, Email = model.Email };
                //var result1 = await UserManager.CreateAsync(user1, model.Password);

                var user = await UserManager.FindByEmailAsync(model.Email);

                if (user == null)
                {
                    return(Json(UserErrors.GetErrorObj(UserErrors.ERROR_USER_PASSWOD_INCORECT)));
                }

                var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

                switch (result)
                {
                case SignInStatus.Success:
                    var address = Url.RouteUrl("AllPages", new { @Controller = "Home", @Action = "Index" }, this.Request.Url.Scheme);
                    return(Json(new { result = "ok", returnUrl = address }));

                case SignInStatus.LockedOut:
                    return(Json(UserErrors.GetErrorObj(UserErrors.ERROR_WRONG_DATA)));

                case SignInStatus.RequiresVerification:
                    return(Json(UserErrors.GetErrorObj(UserErrors.ERROR_WRONG_DATA)));

                case SignInStatus.Failure:
                default:
                    return(Json(UserErrors.GetErrorObj(UserErrors.ERROR_USER_PASSWOD_INCORECT)));
                }
            }
            return(Json(UserErrors.GetErrorObj(UserErrors.ERROR_USER_PASSWOD_INCORECT)));
        }
Beispiel #14
0
 public UserException(IdentityResult result, int code = 400) : this(code)
 {
     UserErrors.AddRange(result.Errors.Select(x => x.Description));
 }
Beispiel #15
0
        /// <summary>
        /// Save selected user
        /// </summary>
        /// <param name="pUser"></param>
        /// <returns>A struct contains, if necessary, errors occurs</returns>
        public UserErrors SaveUser(User pUser)
        {
            UserErrors userErrors = new UserErrors();

            if (pUser.UserName == null)
            {
                userErrors.FindError = true;
                userErrors.LoginError = true;
               // userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Login_Empty.Text");
            }

            if (pUser.Password == null)
            {
                userErrors.FindError = true;
                userErrors.PasswordError = true;
               // userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Password_Empty.Text");
            }

            if (pUser.UserRole == null)
            {
                userErrors.FindError = true;
                userErrors.RoleError = true;
               // userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Role_Empty.Text");
            }
            if (pUser.UserRole.Id < 1)
            {
                userErrors.FindError = true;
                userErrors.RoleError = true;
               // userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Role_Empty.Text");
            }
            if (pUser.FirstName == null)
            {
                userErrors.FindError = true;
                userErrors.FirstNameError = true;
              //  userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_LastName_Empty.Text");
            }

            if (pUser.LastName == null)
            {
                userErrors.FindError = true;
                userErrors.LastNameError = true;
               // userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_FirstName_Empty.Text");
            }

            if (pUser.Mail == null)
            {
                userErrors.FindError = true;
                userErrors.MailError = true;
               // userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Mail_Empty.Text");
            }

            if (userErrors.FindError) return userErrors;

            if (pUser.Id == 0)
            {
                if (Find(pUser.UserName, pUser.Password) != null)
                {
                    userErrors.FindError = true;
               //     userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Save_AlreadyExist.Text");
                }
                else
                {
                    _userManager.AddUser(pUser);
                    if (_users != null) _users.Add(pUser);
                 //   userErrors.ResultMessage = MultiLanguageStrings.GetString(Ressource.StringRes, "User_Save_OK.Text");
                }
            }
            else
            {
                _userManager.UpdateUser(pUser);
                //userErrors.ResultMessage = MultiLanguageStrings.GetString(Ressource.StringRes, "User_Update_OK.Text");
            }

            return userErrors;
        }
        public ActionResult ChangePassword(int userId, string currentPassword, string newPassword, UserErrors userModel)
        {
            if (!ModelState.IsValid) //Checks if input fields have the correct format
            {
                return(View());      //Returns the view with the input values so that the user doesn't have to retype again
            }
            using (ResourcingToolConnection db = new ResourcingToolConnection())
            {
                // hash the password and compare against database
                if (!(userId == null || currentPassword == null))
                {
                    var hashedPassword = Sha256encrypt(currentPassword);
                    var leaderDetails  = db.Users.Where(x => x.Id == userId && x.Password == hashedPassword).FirstOrDefault();

                    if (leaderDetails != null)
                    {
                        var newHashedPassword = Sha256encrypt(newPassword);
                        db.Set <User>().SingleOrDefault(o => o.Id == userId).Password = newHashedPassword;
                        db.SaveChanges();

                        return(RedirectToAction("Index", "Projects"));
                    }
                    else
                    {
                        //User authentication failed
                        userModel.ErrorMessage = "The current password you've entered is incorrect. Please try again.";
                        return(View(userModel));
                    }
                }
                else
                {
                    userModel.ErrorMessage = "Please enter your current password and your new password.";
                    //User authentication failed - blank
                }
            }
            return(View(userModel)); //Should always be declared on the end of an action method
        }
Beispiel #17
0
        /// <summary>
        /// Save selected user
        /// </summary>
        /// <param name="pUser">User to save</param>
        /// <param name="saveSecret">Option to save user password, default false</param>
        /// <returns>A struct contains, if necessary, errors occurs</returns>
        public UserErrors SaveUser(User pUser, bool saveSecret = false)
        {
            UserErrors userErrors = new UserErrors();

            if (pUser.UserName == null)
            {
                userErrors.FindError      = true;
                userErrors.LoginError     = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Login_Empty.Text");
            }

            var passwordValidator = new Regex(@"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{10,}$");

            if (!passwordValidator.IsMatch(pUser.Password))
            {
                userErrors.FindError      = true;
                userErrors.PasswordError  = true;
                userErrors.ResultMessage += "\n - Password must contain " +
                                            "\n• At least one upper case " +
                                            "\n• At least one lower case " +
                                            "\n• At least one digit  " +
                                            "\n• At least one special character  " +
                                            "\n• Minimum 8 in length";
            }
            if (pUser.Password == null)
            {
                userErrors.FindError      = true;
                userErrors.PasswordError  = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Password_Empty.Text");
            }

            if (pUser.UserRole == null)
            {
                userErrors.FindError      = true;
                userErrors.RoleError      = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Role_Empty.Text");
            }
            if (pUser.UserRole.Id < 1)
            {
                userErrors.FindError      = true;
                userErrors.RoleError      = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Role_Empty.Text");
            }
            if (pUser.FirstName == null)
            {
                userErrors.FindError      = true;
                userErrors.FirstNameError = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_LastName_Empty.Text");
            }

            if (pUser.LastName == null)
            {
                userErrors.FindError      = true;
                userErrors.LastNameError  = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_FirstName_Empty.Text");
            }

            if (pUser.Mail == null)
            {
                userErrors.FindError      = true;
                userErrors.MailError      = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Mail_Empty.Text");
            }

            if (String.IsNullOrEmpty(pUser.Secret.Question))
            {
                userErrors.FindError           = true;
                userErrors.SecretQuestionError = true;
                userErrors.ResultMessage      += "\n - " + "Screst question is empty";
            }

            if (String.IsNullOrEmpty(pUser.Secret.Answer))
            {
                userErrors.FindError = true;
                userErrors.SecretQuestionAnswerError = true;
                userErrors.ResultMessage            += "\n - " + "Screst question answer is empty";
            }

            Debug.Assert(OGender.CheckGender(pUser.Sex), string.Format("Non valid gender character is given for user: {0}", pUser.Name));

            if (userErrors.FindError)
            {
                return(userErrors);
            }

            if (pUser.Id == 0)
            {
                if (Find(pUser.UserName, pUser.Password) != null)
                {
                    userErrors.FindError      = true;
                    userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Save_AlreadyExist.Text");
                }
                else
                {
                    _userManager.AddUser(pUser);
                    if (_users != null)
                    {
                        _users.Add(pUser);
                    }
                    userErrors.ResultMessage = MultiLanguageStrings.GetString(Ressource.StringRes, "User_Save_OK.Text");
                }
            }
            else
            {
                _userManager.UpdateUser(pUser, saveSecret);
                if (_users != null)
                {
                    _users.Remove(_users.Where(u => u.UserName == pUser.UserName).FirstOrDefault());
                    _users.Add(pUser);
                }
                userErrors.ResultMessage = MultiLanguageStrings.GetString(Ressource.StringRes, "User_Update_OK.Text");
            }

            return(userErrors);
        }
Beispiel #18
0
        /// <summary>
        /// Save selected user
        /// </summary>
        /// <param name="pUser"></param>
        /// <returns>A struct contains, if necessary, errors occurs</returns>
        public UserErrors SaveUser(User pUser)
        {
            var userErrors = new UserErrors();

            if (pUser.UserName == null)
            {
                userErrors.FindError      = true;
                userErrors.LoginError     = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Login_Empty.Text");
            }

            if (pUser.Password == null)
            {
                userErrors.FindError      = true;
                userErrors.PasswordError  = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Password_Empty.Text");
            }

            if (pUser.UserRole == null)
            {
                userErrors.FindError      = true;
                userErrors.RoleError      = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Role_Empty.Text");
            }
            if (pUser.UserRole.Id < 1)
            {
                userErrors.FindError      = true;
                userErrors.RoleError      = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Role_Empty.Text");
            }
            if (pUser.FirstName == null)
            {
                userErrors.FindError      = true;
                userErrors.FirstNameError = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_LastName_Empty.Text");
            }

            if (pUser.LastName == null)
            {
                userErrors.FindError      = true;
                userErrors.LastNameError  = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_FirstName_Empty.Text");
            }

            if (pUser.Mail == null)
            {
                userErrors.FindError      = true;
                userErrors.MailError      = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Mail_Empty.Text");
            }

            Debug.Assert(OGender.CheckGender(pUser.Sex), string.Format("Non valif geder character is given for user: {0}", pUser.Name));


            if (pUser.Id == 0 && Find(pUser.UserName, pUser.Password) != null)
            {
                userErrors.FindError      = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Save_AlreadyExist.Text");
            }

            if (!string.IsNullOrEmpty(pUser.Password) && (pUser.Password.Length < 4 || pUser.Password.Length > 30))
            {
                userErrors.FindError      = true;
                userErrors.PasswordError  = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Password_Short_Long.Text");
            }

            return(userErrors.FindError ? userErrors : SaveUserInternal(pUser));
        }
Beispiel #19
0
        /// <summary>
        /// Save selected user
        /// </summary>
        /// <param name="pUser"></param>
        /// <returns>A struct contains, if necessary, errors occurs</returns>
        public UserErrors SaveUser(User pUser)
        {
            UserErrors userErrors = new UserErrors();

            if (pUser.UserName == null)
            {
                userErrors.FindError = true;
                userErrors.LoginError = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Login_Empty.Text");
            }

            if (pUser.Password == null)
            {
                userErrors.FindError = true;
                userErrors.PasswordError = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Password_Empty.Text");
            }

            if (pUser.UserRole == null)
            {
                userErrors.FindError = true;
                userErrors.RoleError = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Role_Empty.Text");
            }
            if (pUser.UserRole.Id < 1)
            {
                userErrors.FindError = true;
                userErrors.RoleError = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Role_Empty.Text");
            }
            if (pUser.FirstName == null)
            {
                userErrors.FindError = true;
                userErrors.FirstNameError = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_LastName_Empty.Text");
            }

            if (pUser.LastName == null)
            {
                userErrors.FindError = true;
                userErrors.LastNameError = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_FirstName_Empty.Text");
            }

            if (pUser.Mail == null)
            {
                userErrors.FindError = true;
                userErrors.MailError = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Mail_Empty.Text");
            }

            Debug.Assert(OGender.CheckGender(pUser.Sex), string.Format("Non valif geder character is given for user: {0}", pUser.Name));

            if (userErrors.FindError) return userErrors;

            if (pUser.Id == 0)
            {
                if (Find(pUser.UserName, pUser.Password) != null)
                {
                    userErrors.FindError = true;
                    userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Save_AlreadyExist.Text");
                }
                else
                {
                    _userManager.AddUser(pUser);
                    if (_users != null) _users.Add(pUser);
                    userErrors.ResultMessage = MultiLanguageStrings.GetString(Ressource.StringRes, "User_Save_OK.Text");
                }
            }
            else
            {
                _userManager.UpdateUser(pUser);
                userErrors.ResultMessage = MultiLanguageStrings.GetString(Ressource.StringRes, "User_Update_OK.Text");
            }

            return userErrors;
        }
Beispiel #20
0
 public async Task AddUserError(UserErrorModel2 error)
 {
     UserErrors = UserErrors.Concat(new[] { error }).ToArray();
     await new UserErrorAdded(error).Raise().ConfigureAwait(false);
 }
Beispiel #21
0
        /// <summary>
        /// Save selected user
        /// </summary>
        /// <param name="pUser"></param>
        /// <returns>A struct contains, if necessary, errors occurs</returns>
        public UserErrors SaveUser(User pUser)
        {
            UserErrors userErrors = new UserErrors();

            if (pUser.UserName == null)
            {
                userErrors.FindError      = true;
                userErrors.LoginError     = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Login_Empty.Text");
            }

            if (pUser.Password == null)
            {
                userErrors.FindError      = true;
                userErrors.PasswordError  = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Password_Empty.Text");
            }

            if (pUser.UserRole == null)
            {
                userErrors.FindError      = true;
                userErrors.RoleError      = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Role_Empty.Text");
            }
            if (pUser.UserRole.Id < 1)
            {
                userErrors.FindError      = true;
                userErrors.RoleError      = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Role_Empty.Text");
            }
            if (pUser.FirstName == null)
            {
                userErrors.FindError      = true;
                userErrors.FirstNameError = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_LastName_Empty.Text");
            }

            if (pUser.LastName == null)
            {
                userErrors.FindError      = true;
                userErrors.LastNameError  = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_FirstName_Empty.Text");
            }

            if (pUser.Mail == null)
            {
                userErrors.FindError      = true;
                userErrors.MailError      = true;
                userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Mail_Empty.Text");
            }

            Debug.Assert(OGender.CheckGender(pUser.Sex), string.Format("Non valif geder character is given for user: {0}", pUser.Name));

            if (userErrors.FindError)
            {
                return(userErrors);
            }

            if (pUser.Id == 0)
            {
                if (Find(pUser.UserName, pUser.Password) != null)
                {
                    userErrors.FindError      = true;
                    userErrors.ResultMessage += "\n - " + MultiLanguageStrings.GetString(Ressource.StringRes, "User_Save_AlreadyExist.Text");
                }
                else
                {
                    _userManager.AddUser(pUser);
                    if (_users != null)
                    {
                        _users.Add(pUser);
                    }
                    userErrors.ResultMessage = MultiLanguageStrings.GetString(Ressource.StringRes, "User_Save_OK.Text");
                }
            }
            else
            {
                _userManager.UpdateUser(pUser);
                userErrors.ResultMessage = MultiLanguageStrings.GetString(Ressource.StringRes, "User_Update_OK.Text");
            }

            return(userErrors);
        }