public ActionResult Edit(UserViewModel model)
        {
            model.UserStates = GetUserStates(); //Reload List For Clean Model

            try
            {
                var svc = new UserAppService();

                var o = new User
                {
                    UserName = model.UserName,
                    
                    UserStateId = model.UserStateId,
                    HasChangePassword = model.HasChangePassword


                };
                if (model.UserId == -1)
                {
                    string salt;
                    var hashedPassword = WebHelper.EncryptPassword(model.Password, out salt);
                    o.Password = hashedPassword;
                    o.Salt = salt;
                }
                else
                {
                    if (String.IsNullOrEmpty(model.Password))
                    {
                        var ousr = new UserAppService().GetUser(model.UserId);

                        o.Password = ousr.Password;
                        o.Salt = ousr.Salt;

                    }
                    else
                    { //GetCurrentData
                        string salt;
                        var hashedPassword = WebHelper.EncryptPassword(model.Password, out salt);
                        o.Password = hashedPassword;
                        o.Salt = salt;
                        
                    }

                }


                if (model.UserId == -1)
                {

                    if(CommonHelper.ExistUserName(model.UserName))
                    {
                        ViewBag.Feed = 2;
                        return View(model);

                    }

                    o.LastLoginDate = DateTime.Now;
                    o.AccessCount = 0;
                    o.TryAccessCount = 0;
                   var userId= svc.AddUser(o);

                    var svcUserRole = new UserRoleAppService();

                    var roles = model.AssignedUserRole.Split(',');
                    foreach (var r in roles)
                    {
                        svcUserRole.AddUserRole(new UserRole { RoleId = Convert.ToInt32(r), UserId = userId });

                    }
                    

                    
                    ViewBag.Feed = 0;
                }
                else
                {
                    o.UserId = model.UserId;
                    o.LastLoginDate = DateTime.Now;
                    if (model.IsDeleteAction == 0)
                    {

                        svc.SaveUser(o);


                        var svcUserRole = new UserRoleAppService();
                        svcUserRole.RemoveUserRoleByUserId(o.UserId);
                        var roles = model.AssignedUserRole.Split(',');
                        foreach (var r in roles)
                        {
                            svcUserRole.AddUserRole(new UserRole { RoleId = Convert.ToInt32(r), UserId = o.UserId });

                        }

                        var eusr = new UserAppService().GetUser(model.UserId);
                        model.UserRoles = eusr.UserRoles.ToList();

                    }
                    else
                    {
                        var svcUserRole = new UserRoleAppService();
                        svcUserRole.RemoveUserRoleByUserId(o.UserId);
                        svc.RemoveUser(model.UserId);
                        model.UserRoles = new List<UserRole>();
                    }
                    ViewBag.Feed = 0;
                }
            }
            catch (Exception)
            {
                ViewBag.Feed = 1;

            }
      
            return View(model);
        }