public AdministrationViewModel(UsersViewModel usersViewModel,
                                FunctionalGroupsViewModel functionalGroupsViewModel,
                                TerminalsViewModel terminalsViewModel)
 {
     UsersViewModel = usersViewModel;
     FunctionalGroupsViewModel = functionalGroupsViewModel;
     TerminalsViewModel = terminalsViewModel;
 }
Exemple #2
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                if (model.Credential != model.VerifyPassword)
                {
                    ModelState.AddModelError("VerifyPassword", "两次密码不一致!");
                    return(View(model));
                }

                var connection = Request.HttpContext.Features.Get <IHttpConnectionFeature>();

                var remoteIpAddress = connection.RemoteIpAddress;  //远程IP地址

                model.IP = remoteIpAddress.ToString();

                var usersViewModel = new UsersViewModel()
                {
                    Id               = Guid.NewGuid(),
                    Sort             = 0,
                    Type             = 0,
                    NickName         = model.NickName,
                    Email            = model.Identifier,
                    RegisterTime     = DateTime.Now,
                    RegisterIp       = model.IP,
                    LastLoginTime    = DateTime.Now,
                    LastLoginIp      = model.IP,
                    LastModifiedTime = DateTime.Now,
                    LastModifiedIp   = model.IP,
                    UserAuths        = new List <UserAuthsViewModel>()
                    {
                        new UserAuthsViewModel()
                        {
                            Id               = Guid.NewGuid(),
                            IdentityType     = "email",
                            Identifier       = model.Identifier,
                            Credential       = model.Credential.ToMd5(),
                            State            = 1,
                            AuthTime         = DateTime.Now,
                            LastModifiedTime = DateTime.Now,
                            Verified         = true,
                        }
                    }
                };

                // 执行添加方法
                //_usersAppService.Register(usersViewModel);
                var response = await _usersAppService.RegisterAsync(usersViewModel);

                // 是否存在消息通知
                if (!_notifications.HasNotifications())
                {
                    ViewBag.Sucesso = "Users Registered!";
                }

                if (response.Success)
                {
                    await SignInAsync(response.Data);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    // 是否存在消息通知
                    if (!_notifications.HasNotifications())
                    {
                        ModelState.AddModelError("VerifyPassword", $"{response.Message}");
                    }
                }

                return(View(model));
            }
            catch (Exception e)
            {
                return(View(e.Message));
            }
        }
 public void ListUsers() {
     var vm = new UsersViewModel(this, _mapper);
     _listUsers.Invoke(new ListUsersRequestModel(), vm);
     _eventBus.Subscribe(vm);
     _shell.ActivateItem(vm);
 }
		/// <summary>
		/// Create the html required to change the current user group to filter users by.
		/// </summary>
		/// <param name="Helper">The Url helper object.</param>
		/// <param name="UserGroup">The user group to generate a link for.</param>
		/// <param name="Model">The view model for the current page.</param>
		/// <returns>A string suitable for MVC to render.</returns>
		public static MvcHtmlString UserGroupLink( this UrlHelper Helper, string UserGroup, UsersViewModel Model )
		{
			StringBuilder Result = new StringBuilder();
			TagBuilder Tag = new TagBuilder( "a" );

			Tag.MergeAttribute( "href", "/Users/Index/" + UserGroup );
			Tag.InnerHtml = UserGroup;
			Result.AppendLine( Tag.ToString() );

			return MvcHtmlString.Create( Result.ToString() );
		}
Exemple #5
0
        public async Task <IActionResult> Post([FromBody] UsersViewModel item)
        {
            var response = await _documentClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseId, collectionId), item);

            return(Ok());
        }
Exemple #6
0
        /// <summary>
        /// Create the html required to change the current user group to filter users by.
        /// </summary>
        /// <param name="Helper">The Url helper object.</param>
        /// <param name="UserGroup">The user group to generate a link for.</param>
        /// <param name="Model">The view model for the current page.</param>
        /// <returns>A string suitable for MVC to render.</returns>
        public static MvcHtmlString UserGroupLink(this UrlHelper Helper, string UserGroup, UsersViewModel Model)
        {
            StringBuilder Result = new StringBuilder();
            TagBuilder    Tag    = new TagBuilder("a");

            Tag.MergeAttribute("href", "/Users/Index/" + UserGroup);
            Tag.InnerHtml = UserGroup;
            Result.AppendLine(Tag.ToString());

            return(MvcHtmlString.Create(Result.ToString()));
        }
Exemple #7
0
        /// <summary>
        /// The details method
        /// Gets information about reservation
        /// </summary>
        public IActionResult Detail(int?id)
        {
            if (GlobalVar.LoggedOnUserId == -1)
            {
                return(RedirectToAction("LogInRequired", "Users"));
            }

            if (id == null || !ReservationExists((int)id))
            {
                return(NotFound());
            }

            Reservation reservation = context.Reservations.Find(id);

            UsersViewModel userVM = new UsersViewModel()
            {
                Id         = reservation.User.Id,
                FirstName  = reservation.User.FirstName,
                MiddleName = reservation.User.MiddleName,
                LastName   = reservation.User.LastName,
                Username   = reservation.User.Username
            };

            RoomsViewModel roomVM = new RoomsViewModel()
            {
                Id         = reservation.Room.Id,
                Capacity   = reservation.Room.Capacity,
                PriceAdult = reservation.Room.PriceAdult,
                PriceChild = reservation.Room.PriceChild,
                Number     = reservation.Room.Number,
                Type       = (RoomTypeEnum)reservation.Room.Type
            };

            var allClients = context.Clients.ToList();

            var allClientReservations = context.ClientReservation.Where(x => x.ReservationId == id).ToList();

            var reservedClients = new List <Client>();

            var availableClients = allClients;

            foreach (var clientReservation in allClientReservations)
            {
                availableClients.RemoveAll(x => x.Id == clientReservation.ClientId);
                var client = (context.Clients.Find(clientReservation.ClientId));
                reservedClients.Add(client);
            }

            var availableClientsVM = availableClients.Select(x => new SelectListItem()
            {
                Text  = x.FirstName + " " + x.LastName + " (" + x.Email + ")",
                Value = x.Id.ToString()
            }).ToList();

            var reservedClientsVM = reservedClients.Select(x => new ClientsViewModel()
            {
                Id        = x.Id,
                FirstName = x.FirstName,
                LastName  = x.LastName,
                Email     = x.Email
            }).ToList();

            var model = new ReservationsViewModel()
            {
                User = userVM,
                Room = roomVM,
                CurrentReservationClientCount = reservedClients.Count(),
                DateOfAccommodation           = reservation.DateOfAccommodation,
                DateOfExemption     = reservation.DateOfExemption,
                IsAllInclusive      = reservation.IsAllInclusive,
                IsBreakfastIncluded = reservation.IsBreakfastIncluded,
                OverallBill         = reservation.OverallBill,
                AvailableClients    = availableClientsVM,
                SignedInClients     = reservedClientsVM
            };

            return(View(model));
        }
Exemple #8
0
 public AddRoleUserCommand(UsersViewModel VM)
 {
     vm = VM;
 }
Exemple #9
0
        public ActionResult UsersUpdate([DataSourceRequest] DataSourceRequest request, UsersViewModel user)
        {
            if (user != null && this.ModelState.IsValid)
            {
                var dbuser = this.UserService.GetById(user.Id);
                if (dbuser != null)
                {
                    dbuser.FirstName = user.FirstName;
                    dbuser.LastName  = user.LastName;
                    dbuser.Email     = user.Email;

                    this.UserService.Update(dbuser, user.Role.ToString());
                }
            }

            return(this.Json(new[] { user }.ToDataSourceResult(request, this.ModelState)));
        }
Exemple #10
0
        public ActionResult UsersDestroy([DataSourceRequest] DataSourceRequest request, UsersViewModel user)
        {
            if (user != null)
            {
                this.UserService.Delete(user.Id);
            }

            return(this.Json(new[] { user }.ToDataSourceResult(request, this.ModelState)));
        }
Exemple #11
0
        public ActionResult UsersCreate([DataSourceRequest] DataSourceRequest request, UsersViewModel user)
        {
            if (user != null && this.ModelState.IsValid)
            {
                var dbuser = new User()
                {
                    FirstName = user.FirstName, LastName = user.LastName, Email = user.Email
                };
                this.UserService.Add(dbuser, user.Role.ToString());
            }

            return(this.Json(new[] { user }.ToDataSourceResult(request, this.ModelState)));
        }
 public AddUserViewController(IntPtr handle) : base(handle)
 {
     //get the current UsersViewModel instance
     _vm = UsersViewModel.GetCurrentUsersViewModel();
 }
        //     var result = await UserHelper.AddFullUserAsync(vm, "824455", owner, "images", "Employees", userConected);

        public async Task <PersonCreationViewModel> AddFullUserAsync(UsersViewModel vm, string password, Owner owner,
                                                                     string rootFolder, string folder, ApplicationUser userConected)
        {
            var newUser = ApplicationUser.Create(owner, vm.Name,
                                                 vm.Address, vm.PhoneNumber,
                                                 vm.Email, vm.Nickname, vm.IsAdmin, vm.IsSupervisor,
                                                 true, vm.IsSeller);

            try
            {
                var result = await AddUserAsync(newUser, password);

                if (result != IdentityResult.Success)
                {
                    return(new PersonCreationViewModel {
                        Success = false
                    });
                }

                await AddClaim(newUser, new Claim("OwnerId", owner.Id.ToString()));

                // await UserHelper.AddClaim(user, new Claim("ShopId", shop.Id.ToString()));
                await AddUserToRoleAsync(newUser, "User");

                //

                var path = string.Empty;

                if (vm.ImageFile != null)
                {
                    path = FileHelper.UploadFile(vm.ImageFile, path, rootFolder, folder, ref owner);
                    _context.Update(owner);
                }

                vm.Imagen = path;

                if (vm.IsAdmin)
                {
                    await CheckRoleAsync("Admin");
                    await AddUserToRoleAsync(newUser, "Admin");
                }

                if (vm.IsSeller)
                {
                    await CheckRoleAsync("Seller");
                    await AddUserToRoleAsync(newUser, "Seller");
                }

                if (vm.IsSupervisor)
                {
                    await CheckRoleAsync("Supervisor");
                    await AddUserToRoleAsync(newUser, "Supervisor");
                }

                await _context.SaveChangesAsync();

                var perView = new PersonCreationViewModel {
                    Success = true
                };

                return(perView);
            }
            catch (Exception)
            {
                return(new PersonCreationViewModel {
                    Success = false
                });
            }
        }
Exemple #14
0
 public UsersView()
 {
     InitializeComponent();
     DataContext = new UsersViewModel();
 }
 private List <User> FilterUsers(UsersViewModel model)
 {
     return(_repository.Users
            .Where(u => u.Name.Contains(model.QueryString))
            .ToList());
 }
Exemple #16
0
 public void Post([FromBody] UsersViewModel u)
 {
     orderService.Register(u.Name, u.Surname, u.Email, u.TelNumb, u.Password);
 }
Exemple #17
0
 /// <summary>
 /// 直接调用仓储新增(几乎不涉及到任何业务逻辑)
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Add(UsersViewModel model)
 {
     ///很多人这里是映射了Command,但本人觉得这造成代码量增加。所以这里直接映射了实体(后果造成代码污染。但这后果我觉得可以忽略不记)
     return(_usersRepository.Insert(_mapper.Map <Users>(model)));
 }
Exemple #18
0
        public void TestMethodAantalUsers()
        {
            var viewmodel = new UsersViewModel();

            Assert.AreEqual(12, viewmodel.Users.Count);
        }
Exemple #19
0
        public IActionResult Maintenance(string submitAction, string originalEmail
                                         , UsersViewModel uvm)
        {
            VerifyParam(() =>
                        submitAction == Constants.SaveAction ||
                        submitAction == Constants.CancelAction ||
                        submitAction == Constants.DeleteAction);
            string maintenanceMode;

            if (submitAction == Constants.DeleteAction)
            {
                maintenanceMode = Constants.UsersDeleteMode;
            }
            else
            {
                maintenanceMode = originalEmail == null ? Constants.UsersCreateMode : Constants.UsersEditMode;
            }

            originalEmail = originalEmail ?? string.Empty;
            if (submitAction == Constants.CancelAction)
            {
                return(RedirectToAction(nameof(Index)));
            }

            if (IsLoggedInUserRecord(uvm))
            {
                if (maintenanceMode == Constants.UsersEditMode && uvm.Role != Role.Admin ||
                    maintenanceMode == Constants.UsersDeleteMode)
                {
                    ModelState.AddModelError(string.Empty
                                             , "You cannot delete your own user record or change the role");
                }
            }
            if (!ModelState.IsValid)
            {
                if (!string.IsNullOrWhiteSpace(uvm.Password))
                {
                    uvm.Password = string.Empty;
                    // if the password field is blank and therefore invalid then
                    // we need to keep it to produce the error message.
                    // if the password field is not blank and some other field
                    // is invalid then we need to remove the password field
                    // to ensure the form returns an empty password field
                    // This will need to change if we introduce more exacting password rules
                    ModelState.Remove(nameof(UsersViewModel.Password));
                    // make sure that the password is not echoed back if validation fails
                }
                new ViewBagConfigurer().ConfigureViewBag(ViewBag, maintenanceMode);
                return(View("Maintenance", uvm));
            }
            ModelState.Remove(nameof(UsersViewModel.Password));
            // make sure that the password is not echoed back if validation fails
            switch (maintenanceMode)
            {
            case Constants.UsersCreateMode:
            case Constants.UsersEditMode:
                return(SaveCreatedOrEditedUser(maintenanceMode, uvm, originalEmail));

            case Constants.UsersDeleteMode:
                return(DeleteUser(uvm));
            }

            new ViewBagConfigurer().ConfigureViewBag(ViewBag, maintenanceMode);
            return(View("Maintenance", uvm));
        }
Exemple #20
0
        public ActionResult Index(int page = 1, string filter = null)
        {
            var vm = new UsersViewModel(UserManagementRepository, page, filter);

            return(View("Index", vm));
        }
Exemple #21
0
        private bool IsLoggedInUserRecord(UsersViewModel uvm)
        {
            var loggedInUserEmail = this.HttpContext.User.Identities.First().Name;

            return(loggedInUserEmail == uvm.EmailAddress);
        }
Exemple #22
0
        public async Task <ActionResult> UsersUpdate([DataSourceRequest] DataSourceRequest request, UsersViewModel user)
        {
            if (user != null && this.ModelState.IsValid)
            {
                await this.UserService.UpdateAsync(user.RowKey, user.Role == MyServerRoles.Admin);
            }

            return(this.Json(new[] { user }.ToDataSourceResult(request, this.ModelState)));
        }
        public IActionResult UpdateUser(UpdateUserViewModel user)
        {
            var success = false;

            if (user.OriginalRoleName != user.RoleName)
            {
                //Do work to remove record from old role and create in new role
                ViewData["Message"] = "Input is not valid";
            }
            else
            {
                //Save user properties
                switch (user.RoleName)
                {
                case "Administrator":
                    var administrator = _db.Administrators.FirstOrDefault(x => x.AdminId == user.UserId);
                    if (administrator != null)
                    {
                        administrator.FirstName    = user.FirstName;
                        administrator.LastName     = user.LastName;
                        administrator.EmailAddress = user.Email;
                        administrator.IsActive     = user.IsActive;
                        _db.SaveChanges();
                        ViewData["Message"] = "Administrator Record Updated Successfully";
                        success             = true;
                    }
                    else
                    {
                        ViewData["Message"] = "Input is not valid";
                    }
                    break;

                case "Professional":
                    var pro = _db.Professionals.FirstOrDefault(x => x.ProfessionalId == user.UserId);
                    if (pro != null)
                    {
                        var professional = _db.Professionals.SingleOrDefault(x => x.ProfessionalId == user.UserId);
                        if (professional != null)
                        {
                            professional.FirstName    = user.FirstName;
                            professional.LastName     = user.LastName;
                            professional.EmailAddress = user.Email;
                            professional.IsActive     = user.IsActive;
                            _db.SaveChanges();
                            ViewData["Message"] = "Professional Record Updated Successfully";
                            success             = true;
                        }
                    }
                    else
                    {
                        ViewData["Message"] = "Input is not valid";
                    }
                    break;

                case "Student":
                    var student = _db.Students.FirstOrDefault(x => x.StudentId == user.UserId);
                    if (student != null)
                    {
                        student.FirstName    = user.FirstName;
                        student.LastName     = user.LastName;
                        student.EmailAddress = user.Email;
                        student.IsActive     = user.IsActive;
                        _db.SaveChanges();
                        ViewData["Message"] = "Student Record Updated Successfully";
                        success             = true;
                    }
                    else
                    {
                        ViewData["Message"] = "Input is not valid";
                    }
                    break;
                }
            }
            if (success)
            {
                return(RedirectToAction("ManageUsers"));
            }

            var roles = new List <string> {
                "Administrator", "Professional", "Student"
            };

            var editUser = new UsersViewModel
            {
                Roles        = roles,
                FirstName    = user.FirstName,
                LastName     = user.LastName,
                Email        = user.Email,
                IsActive     = user.IsActive,
                UserId       = user.UserId,
                RoleName     = user.OriginalRoleName,
                ErrorMessage = ViewData["Message"].ToString()
            };

            return(View("EditUser", editUser));
        }
Exemple #24
0
 public UsersPage()
 {
     InitializeComponent();
     BindingContext = new UsersViewModel();
 }
        public async Task <IActionResult> CreateOrUpdate(UsersViewModel viewModel)
        {
            ViewBag.Roles = _roleManager.GetAllRoles();
            if (viewModel.Id != null)
            {
                ModelState.Remove("Password");
                ModelState.Remove("ConfirmPassword");
                ModelState.Remove("ImageFile");
            }

            if (ModelState.IsValid)
            {
                IdentityResult result = null;
                if (viewModel.ImageFile != null)
                {
                    viewModel.Image = _userManager.CheckAvatarFileName(viewModel.ImageFile.FileName);
                }

                viewModel.Roles = new List <UserRole> {
                    new UserRole {
                        RoleId = (int)viewModel.RoleId
                    }
                };
                viewModel.BirthDate = viewModel.PersianBirthDate.ConvertShamsiToMiladi();
                if (viewModel.Id != null)
                {
                    var user = await _userManager.FindByIdAsync(viewModel.Id.ToString());

                    user.FirstName   = viewModel.FirstName;
                    user.LastName    = viewModel.LastName;
                    user.BirthDate   = viewModel.BirthDate;
                    user.Email       = viewModel.Email;
                    user.UserName    = viewModel.UserName;
                    user.Gender      = viewModel.Gender.Value;
                    user.PhoneNumber = viewModel.PhoneNumber;
                    user.Roles       = viewModel.Roles;
                    user.Bio         = viewModel.Bio;
                    var userRoles = await _userManager.GetRolesAsync(user);

                    if (viewModel.ImageFile != null)
                    {
                        await viewModel.ImageFile.UploadFileAsync($"{_env.WebRootPath}/avatars/{viewModel.Image}");

                        FileExtensions.DeleteFile($"{_env.WebRootPath}/avatars/{user.Image}");
                        user.Image = viewModel.Image;
                    }

                    result = await _userManager.RemoveFromRolesAsync(user, userRoles);

                    if (result.Succeeded)
                    {
                        result = await _userManager.UpdateAsync(user);
                    }
                }

                else
                {
                    await viewModel.ImageFile.UploadFileAsync($"{_env.WebRootPath}/avatars/{viewModel.Image}");

                    viewModel.EmailConfirmed = true;
                    result = await _userManager.CreateAsync(_mapper.Map <User>(viewModel), viewModel.Password);
                }

                if (result.Succeeded)
                {
                    TempData["notification"] = OperationSuccess;
                }
                else
                {
                    ModelState.AddErrorsFromResult(result);
                }
            }

            return(PartialView("_RenderUser", viewModel));
        }
Exemple #26
0
 public UsersView(UsersViewModel viewModel) : this()
 {
     DataContext = viewModel;
 }
Exemple #27
0
 public IActionResult EditUser(UsersViewModel userviewmodel)
 {
     return(View("ViewEditUser", userviewmodel));
 }
Exemple #28
0
 public ItemsDataSource(UsersViewModel viewModel)
 {
     this.viewModel = viewModel;
 }
Exemple #29
0
 /// <summary>
 /// Initializes the users window
 /// </summary>
 private void initializeUsersWindow()
 {
     this.usersWindow = new UsersViewModel();
     this.usersWindow.addBuddyList += addToBuddyList;
     this.usersWindow.wind.sendPM  += sendPM;
 }