예제 #1
0
        public async Task <IActionResult> SaveAppUser(AppUserView viewModel)
        {
            if (ModelState.IsValid)
            {
                AppUser user = new AppUser
                {
                    FirstName   = viewModel.FirstName,
                    LastName    = viewModel.LastName,
                    UserName    = viewModel.UserName,
                    Email       = viewModel.Email,
                    PhoneNumber = viewModel.PhoneNumber,
                    UserType    = UserType.STAFF.ToString()
                };

                IdentityResult result
                    = await _userManager.CreateAsync(user, viewModel.Password);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    foreach (IdentityError error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                }
            }
            return(View("AddAppUser", viewModel));
        }
예제 #2
0
        private AppUserView GetUserInfo(int userId)
        {
            var data = new AppUserView();
            var uv   = _userBusiness.GetUserInfo(userId);

            if (uv == null)
            {
                return(data);
            }
            data.Id           = uv.Id;
            data.NickName     = uv.NickName;
            data.Picture      = uv.Picture;
            data.Account      = uv.Account;
            data.Pwd          = uv.Pwd;
            data.PlayCount    = uv.PlayCount;
            data.FansCount    = uv.FansCount;
            data.SkinId       = uv.SkinId;
            data.BannerImage  = uv.BannerImage;
            data.Bardian      = uv.Bardian;
            data.Phone        = uv.Phone;
            data.SubscribeNum = uv.SubscribeNum;
            data.Level        = uv.Level;
            data.State        = uv.State;
            data.IsSubed      = uv.IsSubed;
            data.Token        = uv.Token;
            data.City         = uv.City;
            data.Gender       = uv.Gender;
            data.Birthdate    = uv.Birthdate;
            return(data);
        }
        public MyUsersResetPasswordPageViewModel(AppUserView user)
        {
            _user = user;
            SetPasswordCommand = new AsyncDelegateCommand(OnSetPassword);
            CloseCommand       = new AsyncDelegateCommand(OnClose);

            Header = string.Format(nameof(AppResources.EnterNewPasswordFor).Translate(),
                                   $"{_user.FirstName} {_user.LastName}");
        }
예제 #4
0
        public async Task <ActionResult> Create(AppUserView model)
        {
            if (ModelState.IsValid)
            {
                //initialise the task creation flags
                bool createUserOnHoldTask = false;

                //Retrieve Branch
                Branch branch = BranchHelpers.GetBranch(db, model.SelectedBranchId.Value);

                //Create a new AppUser then write here
                AppUser appUser = AppUserHelpers.CreateAppUser(model.FirstName, model.LastName, branch.BranchId, model.EntityStatus, model.Email, model.PrivacyLevel, model.UserRole);

                BranchUser branchUser = null;

                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, AppUserId = appUser.AppUserId, FullName = model.FirstName + " " + model.LastName, CurrentUserRole = model.UserRole
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //set on-hold task flag
                    if (model.EntityStatus == EntityStatusEnum.OnHold)
                    {
                        createUserOnHoldTask = true;
                    }

                    //Now Update related entities
                    //BranchUser - set the status as ACTIVE as the link is active even though the entities linked are not.
                    branchUser = BranchUserHelpers.CreateBranchUser(appUser.AppUserId, branch.BranchId, branch.CompanyId, model.UserRole, EntityStatusEnum.Active);

                    //Task creation
                    if (createUserOnHoldTask)
                    {
                        UserTaskHelpers.CreateUserTask(TaskTypeEnum.UserOnHold, "New user on hold, awaiting administrator/manager activation", appUser.AppUserId, appUser.AppUserId, EntityStatusEnum.Active);
                    }

                    return(RedirectToAction("UserAdmin", "Admin"));
                }

                //Delete the appUser account as this has not gone through
                AppUserHelpers.DeleteAppUser(appUser.AppUserId);
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form - set up the drop downs dependant on what was there originally from the model
            Branch userBranch = BranchHelpers.GetCurrentBranchForUser(AppUserHelpers.GetGuidFromUserGetAppUserId(User.Identity.GetAppUserId()));

            //DropDown
            ViewBag.BranchList       = ControlHelpers.AllBranchesForCompanyListDropDown(userBranch.CompanyId, userBranch.BranchId);
            ViewBag.UserRoleList     = ControlHelpers.UserRoleEnumListDropDown();
            ViewBag.EntityStatusList = ControlHelpers.EntityStatusEnumListDropDown();

            return(View(model));
        }
 public UserDetailPageViewModel(AppUserView selectedUser)
 {
     User = selectedUser;
     ToggleHeaderFrameCommand  = new Command <bool>((show) => ShowHeaderFrame = show);
     ToggleActionsFrameCommand = new Command <bool>((show) => ShowActionsFrame = show);
     EditUserCommand           = new AsyncDelegateCommand(OnEdit);
     DeleteUserCommand         = new AsyncDelegateCommand(OnDelete);
     ResetPasswordCommand      = new AsyncDelegateCommand(OnResetPassword);
     ShowHeaderFrame           = true;//Requested by Bassam to show user details as default
 }
예제 #6
0
 public AddUserPageViewModel(AppUserView user = null)
 {
     AddCommand   = new AsyncDelegateCommand(OnAdd);
     CloseCommand = new AsyncDelegateCommand(OnClose);
     User         = new AddAppUserView();
     RoleList     = new ObservableCollection <KeyValuePair <AddAppUserViewRole, string> >
     {
         new KeyValuePair <AddAppUserViewRole, string>(AddAppUserViewRole.None, "None"),
         new KeyValuePair <AddAppUserViewRole, string>(AddAppUserViewRole.Plant_Admin, "Plant Admin"),
         new KeyValuePair <AddAppUserViewRole, string>(AddAppUserViewRole.Plant_Viewer, "Plant Viewer"),
         new KeyValuePair <AddAppUserViewRole, string>(AddAppUserViewRole.Sales_Rep, "Sales Rep"),
     };
     SelectedRole = _roleList.First();
 }
        public AppUserView Get(int id)
        {
            var userView = new AppUserView();
            var user     = db.AppUsers.Find(id);

            if (user != null)
            {
                userView.DisplayName = user.DisplayName;
                userView.Id          = id;
                userView.Image       = user.Image;
                userView.ImageUrl    = user.ImageUrl;
            }

            return(userView);
        }
예제 #8
0
        private void CreateProduct(int numberProduct, bool isPending = false)
        {
            IEnumerable <Category>    listCategory  = _unitOfWork.Category.GetAll();
            IEnumerable <AppUserView> BestSuppliers = _unitOfWork.SP.ReturnList <AppUserView>("SelectTopSeller");

            for (int i = 1; i <= numberProduct; i++)
            {
                foreach (Category cat in listCategory)
                {
                    IEnumerable <Unit> unitList = _unitOfWork.Unit.GetAll(filter: u => u.CategoryId == cat.Id);
                    Random             random   = new Random();
                    int         index           = random.Next(0, BestSuppliers.Count() - 1);
                    AppUserView selectedUser    = BestSuppliers.ToArray()[index];

                    string productName = "Great" + cat.Name + "No " + i.ToString();

                    Product product = new Product()
                    {
                        Name        = productName,
                        Description = productName + " is one of the most famous food in Vietnam.",
                        Price       = 10 * i / 0.5 + (15 * cat.Id * 0.3),
                        UnitId      = unitList.ToArray()[0].Id,
                        CategoryId  = cat.Id,
                        CreateDate  = DateTime.Now,
                        AvgRating   = i * 2,
                        Status      = isPending ? ProductStatus.Pending : ProductStatus.Active,
                        UserId      = selectedUser.Id
                    };

                    _unitOfWork.Product.Add(product);

                    PricingHistory pricing = new PricingHistory()
                    {
                        Product    = product,
                        OPrice     = 0,
                        NPrice     = product.Price,
                        UpdateDate = product.CreateDate,
                        UserId     = product.UserId
                    };
                    _unitOfWork.PricingHistory.Add(pricing);

                    _unitOfWork.Save();
                }
            }
        }
        public async Task <IEnumerable <AppUserView> > GetConnectedUsersAsync(Func <IEnumerable <User> > getCurrnetUserFn)
        {
            ICollection <AppUserView> ret = new List <AppUserView>();
            var users = getCurrnetUserFn();

            if (!users.IsEmptyList())
            {
                using (var db = ionixFactory.CreateDbContext())
                {
                    foreach (User user in users)
                    {
                        AppUserView entity = await db.AppUsers.QuerySingleViewByAsync(user.Name);

                        if (null != entity)
                        {
                            ret.Add(entity);
                        }
                    }
                }
            }

            return(ret);
        }
 public EditUserPageViewModel(AppUserView user)
 {
     SaveCommand  = new AsyncDelegateCommand(OnSave);
     CloseCommand = new AsyncDelegateCommand(OnClose);
     _userParam   = user;
 }
 public EditUserPage(AppUserView user)
 {
     InitializeComponent();
     BindingContext = _vm = new EditUserPageViewModel(user);
 }
 public MyUsersResetPasswordPage(AppUserView user)
 {
     InitializeComponent();
     BindingContext = _vm = new MyUsersResetPasswordPageViewModel(user);
 }
        public Task <AppUserView> QuerySingleViewByAsync(string userName)
        {
            var q = AppUserView.Query().ToInnerQuery("t").Sql(" where t.user_name=:0", userName);

            return(this.Cmd.QuerySingleAsync <AppUserView>(q));
        }
 public Task <IList <AppUserView> > QueryViewAsync() => this.Cmd.QueryAsync <AppUserView>(AppUserView.Query());
 public UserDetailPage(AppUserView selectedUser)
 {
     InitializeComponent();
     BindingContext = _vm = new UserDetailPageViewModel(selectedUser);
 }
예제 #16
0
 public AddUserPage(AppUserView user = null)
 {
     InitializeComponent();
     BindingContext = _vm = new AddUserPageViewModel(user);
 }
예제 #17
0
 public async Task <ApiResponseOfAppUserView> EditUser(AppUserView context)
 {
     return(await AXClient.Instance.EditUserAsync(context)
            .ConfigureAwait(false));
 }