private void Button_Click_Unban(object sender, RoutedEventArgs e) { var userServiceModel = new UserServiceModel(); userService.UpdateUser(this.UserId, null, null, null, null, null, null, null, 0, null, null); this.NavigationService.Navigate(new ListUsersPage()); }
public void UpdateUser(UserServiceModel userModel) { var user = _userRepository.GetByID(userModel.Id); if (user == null) { throw new Exception(Resources.ValidationUserNotFound); } else { user.FirstName = userModel.FirstName; user.LastName = userModel.LastName; user.Avatar = userModel.Avatar; user.BirthDate = userModel.BirthDate; user.Budget = userModel.Budget; _userRepository.Update(user); _userRepository.Complete(); if (_userRepository.IsError) { throw new Exception(Resources.TextAbort); } } }
public IActionResult Edit(EditBindingModel input) { if (!userService.Contains(input.Id)) { return(Redirect("/User/All?page=1&showBy=10&orderBy=usernameAsc")); } if (!ModelState.IsValid) { return(Redirect("/User/All?page=1&showBy=10&orderBy=usernameAsc")); } var serviceModel = new UserServiceModel { Address = input.Address, EGN = input.EGN, FirstName = input.FirstName, Id = input.Id, LastName = input.LastName }; userService.Edit(serviceModel); return(Redirect("/User/All?page=1&showBy=10&orderBy=usernameAsc")); }
public async Task <UserServiceModel> GetUserAsync(int id) { _logger.LogInformation($"AccountService (GetUserAsync) - {id}"); var user = await _unitOfWork.Users.GetByIdAsync(id); var roles = await _unitOfWork.Roles.GetAllAsync(); var userRoles = await Task.Run(() => _unitOfWork.UserRoles.Get(r => r.UserId == user.Id)); var assignedRoles = (from ur in userRoles.AsEnumerable() join rl in roles on ur.RoleId equals rl.Id select new RoleServiceModel { Id = ur.RoleId, RoleName = rl.RoleName }).ToList(); var userServiceModel = new UserServiceModel { Id = user.Id, UserName = user.Email, AssignedRoles = assignedRoles }; return(userServiceModel); }
/// <summary> /// Upsert de Food Restrictions /// </summary> /// <param name="serviceModel"></param> public static void UpsertFoodRestrictions(UserServiceModel serviceModel) { var user = _db.UserFood.First(x => x.codUserFood == serviceModel.UserId); //Adicionando as novas foodrestricions que ainda não existem associados ao User foreach (var foodRestriction in serviceModel.Restrictions) { if (!user.userFoodRestriction.Any(x => x.foodRestriction.ToLower().Trim() == foodRestriction.ToLower().Trim())) { var newFoodRestriction = new UserFoodRestriction() { codUserFoodFK = serviceModel.UserId, foodRestriction = foodRestriction }; _db.UserFoodRestriction.Add(newFoodRestriction); } } _db.SaveChanges(); //Removendo possÃveis FoodRestrictions removidas pela request foreach (var foodRestriction in user.userFoodRestriction.Where(x => !serviceModel.Restrictions.Any(y => y == x.foodRestriction))) { _db.UserFoodRestriction.Remove(foodRestriction); } _db.SaveChanges(); }
public async Task <IActionResult> FoodRestriction(UserServiceModel request) { try { var client = new HttpClient(); var retryPolicy = _policyRegistry.Get <IAsyncPolicy <HttpResponseMessage> >(PolicyNames.BasicRetry) ?? Policy.NoOpAsync <HttpResponseMessage>(); var context = new Context($"GetSomeData-{Guid.NewGuid()}", new Dictionary <string, object> { { PolicyContextItems.Logger, _logger }, { "UserServiceModel", request } }); var response = await retryPolicy.ExecuteAsync(async() => { return(await UpsertFoodRestrictions(request)); }); return(Ok()); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public string SaveUserDetails(UserServiceModel UserDetails) { var user = new UserModel() { Id = UserDetails.Id, Cellphone = UserDetails.Cellphone, CompanyId = UserDetails.CompanyId, EmergencyContact = UserDetails.EmergencyContact, EmergencyContactNo = UserDetails.EmergencyContactNo, Email = UserDetails.Email, EndTime = UserDetails.EndTime, FirstName = UserDetails.FirstName, Password = UserDetails.Password, StartTime = UserDetails.StartTime, SurName = UserDetails.SurName, UserGroups = UserDetails.UserGroups, UserName = UserDetails.UserName, UserStatus = UserDetails.UserStatus, UserTeamId = UserDetails.UserTeamId, UserToken = UserDetails.UserToken, UserType = UserDetails.UserType, WorkingDays = UserDetails.WorkingDays }; return(_IUserRepository.SaveUserDetails(user)); }
public async Task <UserServiceModel> GetUserAsync(LoginServiceModel model) { _logger.LogInformation($"AccountService (GetUser) - {model.Email}"); var hashPassword = HashPasswordService.GetHshedPassword(model.Password); var user = await Task.Run(() => _unitOfWork.Users.Get(u => u.Email == model.Email && u.Password == hashPassword).FirstOrDefault()); if (user == null) { return(null); } var userRoles = await Task.Run(() => _unitOfWork.UserRoles.Get(r => r.UserId == user.Id)); var roles = await _unitOfWork.Roles.GetAllAsync(); var assignedRoles = from ur in userRoles.AsEnumerable() join rl in roles on ur.RoleId equals rl.Id select new RoleServiceModel { Id = ur.RoleId, RoleName = rl.RoleName }; var userServiceModel = new UserServiceModel { Id = user.Id, UserName = user.Email, AssignedRoles = assignedRoles.ToList() }; return(userServiceModel); }
public JsonResult SaveUserService(UserServiceModel model) { try { var userService = db.UsersServices.Where(x => x.ServiceID == model.ServiceID && x.UserID == model.UserID).FirstOrDefault(); if (userService != null) { userService.InterestedValue = model.InterestedValue; userService.UserID = model.UserID; userService.ServiceID = model.ServiceID; db.SaveChanges(); } else { userService = new UsersService(); userService.InterestedValue = model.InterestedValue; userService.UserID = model.UserID; userService.ServiceID = model.ServiceID; db.UsersServices.Add(userService); db.SaveChanges(); model.UsersServicesID = userService.UsersServicesID; } return(Json(true, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> SetTaskCompletion(Guid taskId, Guid userId, [FromBody] TaskCompletionModel task) { UserServiceModel user = await _userService.GetByPrincipalAsync(User); if (user == null || user.Id != userId) { return(Unauthorized()); } if (taskId != task.Id) { return(BadRequest()); } TaskServiceModel taskServiceModel = await _taskService.GetByIdAsync(taskId); if (taskServiceModel == null) { return(NotFound()); } await _taskService.TaskCompletion(taskId, task.IsDone); return(NoContent()); }
public static void UpdateUser(this UserServiceModel user, UserViewModel userViewModel) { user.UserId = userViewModel.UserId; user.UserName = userViewModel.UserName; user.FullName = userViewModel.FullName; user.Email = userViewModel.Email; user.PhoneNumber = userViewModel.PhoneNumber; user.Address = userViewModel.Address; user.City = userViewModel.City; user.Area = userViewModel.Area; user.Status = userViewModel.Status; user.IsSystemAccount = userViewModel.IsSystemAccount; user.LockoutEnabled = userViewModel.LockoutEnabled; user.LockoutEndDateUtc = userViewModel.LockoutEndDateUtc; user.RoleName = userViewModel.RoleName; user.PhoneNumberConfirmed = userViewModel.PhoneNumberConfirmed; user.DOB = userViewModel.DOB; user.Funcs = userViewModel.Funcs.Select(x => new FunctionServiceModel { Controller = x.Controller, FunctionId = x.FunctionId, FunctionName = x.FunctionName, FunctionType = x.FunctionType, ModuleCode = x.ModuleCode, Status = x.Status }); }
public UserServiceModel GetUserByUsername(string username) { var reader = this.ExecuteReader(QueryConstants.GetUserByUsername, new Dictionary <string, object> { { "@username", username } }); var counter = 0; UserServiceModel user = null; while (reader.Read()) { counter++; var userId = (int)reader[0]; var usernameDb = (string)reader[1]; var firstName = (string)reader[2]; var lastName = (string)reader[3]; var email = (string)reader[4]; var imageUrl = (string)reader[5]; var passwordHash = (string)reader[6]; var passwordSalt = (string)reader[7]; var role = (string)reader[8]; user = new UserServiceModel(userId, username, firstName, lastName, email, imageUrl, role, passwordHash, passwordSalt); } if (counter > 1) { throw new InvalidOperationException("Username must be unique"); } return(user); }
public ActionResult Login() { Utility utility = new Utility(); UserServiceModel dbUser = new UserServiceModel(); if (Membership.GetUser("admin") == null) { MembershipCreateStatus status; // Generate a new 12-character password with 1 non-alphanumeric character. //y0t(9ci&xUn^ string password = utility.GetUniqueKey(8); //Membership.GeneratePassword(8, 0); // string password = "******"; SMIM_UserMst_ST userentity = new SMIM_UserMst_ST(); userentity.UserName = "******"; userentity.UserTypeId = 1;//db.HRMS_UserType_ST.Where(x => x.Description == "Admin").Select(x => x.UserTypeId).FirstOrDefault(); userentity.FirstName = "admin"; userentity.LastName = "admin"; userentity.Email = "*****@*****.**"; userentity.CreateOn = System.DateTime.Now; userentity.CreatedBy = 0; dbUser.InsertUser(userentity); MembershipUser newUser = Membership.CreateUser("admin", password, "admin", "ok", "ok", true, out status); utility.sendMail("*****@*****.**", "Admin Credential", "Admin User created successfully<br/> Password is " + password); } return(View()); }
public async Task <List <UserServiceModel> > GetUsersAsync() { _logger.LogInformation($"AccountService (GetUsersAsync) "); var userServiceCollection = new List <UserServiceModel>(); var users = await _unitOfWork.Users.GetAllAsync(); var roles = await _unitOfWork.Roles.GetAllAsync(); foreach (var user in users) { var userRoles = _unitOfWork.UserRoles.Get(r => r.UserId == user.Id); var assignedRoles = (from ur in userRoles.AsEnumerable() join rl in roles on ur.RoleId equals rl.Id select new RoleServiceModel { Id = ur.RoleId, RoleName = rl.RoleName }).ToList(); var userServiceModel = new UserServiceModel { Id = user.Id, UserName = user.Email, AssignedRoles = assignedRoles }; userServiceCollection.Add(userServiceModel); } return(userServiceCollection); }
public UserServiceModel GetInfoUserById(int id) { var user = _uow.User.GetUserById(id); if (user == null) { return(null); } else { var houseInfo = _uow.House.GetHouseById(user.HouseId); var block = _uow.Block.GetBlockById(houseInfo.BlockId); var result = new UserServiceModel { Id = user.Id, Username = user.Username, Fullname = user.Fullname, DateOfBirth = user.DateOfBirth, Idnumber = user.Idnumber, IdcreatedDate = user.IdcreatedDate, HouseName = houseInfo.HouseName, Floor = houseInfo.Floor, BlockName = block.BlockName, Gender = user.Gender, ProfileImage = user.ProfileImage, SendPasswordTo = user.SendPasswordTo }; return(result); } }
public async Task <UserServiceModel> GetUserInfo(Guid id) { UserDTO userDTO = await _uow.Users.GetUserInfo(id); UserServiceModel userServiceModel = _mapper.Map <UserDTO, UserServiceModel>(userDTO); return(userServiceModel); }
public async Task <IdentityResult> CreateUserAsync(UserServiceModel user, string password) { var model = _mapper.Map <WebUser>(user); IdentityResult res = await _userManager.CreateAsync(model, password); user.Id = model.Id; return(res); }
public async Task <UserServiceModel> GetByIdAsync(Guid id) { User user = await _userManager.FindByIdAsync(id.ToString()); UserServiceModel userServiceModel = _mapper.Map <User, UserServiceModel>(user); return(userServiceModel); }
private async Task <HttpResponseMessage> UpsertFoodRestrictions(UserServiceModel request) { var responseMessage = new HttpResponseMessage(); UserService.UpsertFoodRestrictions(request); return(responseMessage); }
// // GET: /CuentaGasto/Create public ActionResult Create() { UserServiceModel us = new UserServiceModel(); var lis = us.getUsersList(); SelectList lista = new SelectList(lis, "CodigoAcreditacion", "Nombre", 0); ViewBag.Lista = lista; return(View()); }
public async Task <UserServiceModel> GetByPrincipalAsync(ClaimsPrincipal principal) { string userId = _userManager.GetUserId(principal); User user = await _userManager.FindByNameAsync(userId); UserServiceModel userServiceModel = _mapper.Map <User, UserServiceModel>(user); return(userServiceModel); }
public UserServiceModel Login(string username, string password) { var hashedPassword = this.GetSha256Hash(password); var user = this.userService.FindByUsernameAndPassword(username, hashedPassword); this.User = user; return(this.User); }
public User UpdateUser(UserServiceModel usr) { User user = new User(); user.Name = usr.Name; user.Surname = usr.Surname; user.Address = usr.Address; user.Birthday = usr.Birthday; user.LastModifiedDate = DateTime.Now; return(_usersRepository.UpdateUser(user)); }
public void UpdateUser(UserServiceModel user) { _unitOfWork.AddRepository <UserEntityModel>(); var userEntity = _mapper.Map <UserEntityModel>(user); _dateService.SetDateEditedNow(ref userEntity); _unitOfWork.GetRepository <UserEntityModel>().Update(userEntity); _unitOfWork.Save(); }
// Edit private void Button_Click(object sender, RoutedEventArgs e) { var userServiceModel = new UserServiceModel(); var errorsWhileEdit = ""; if (Birthday.Text.Length == 0) { errorsWhileEdit = "Invalid Birthday \n"; } if (FullNameText.Text.Length == 0) { errorsWhileEdit += "Invalid Full name \n"; } if (PasswordText.Password.Length > 0) { if (PasswordText.Password.Length <= 4) { errorsWhileEdit += "Invalid Password \n"; } if (ConfirmationPasswordNameText.Password.Length <= 4) { errorsWhileEdit += "Invalid Confirmation Password \n"; } if (PasswordText.Password != ConfirmationPasswordNameText.Password) { errorsWhileEdit += "Password and confirmation password do not match. \n"; } } if (errorsWhileEdit != "") { MessageBox.Show("Please check the following fields: \n" + errorsWhileEdit); } else { userService.UpdateUser(this.UserId, FullNameText.Text, DescriptionText.Text, null, DateTime.Parse(Birthday.Text), PasswordText.Password.ToString(), Convert.ToInt32(ActiveCheckbox.IsChecked), null, null, Convert.ToBoolean(UserRoleRadioButton.IsChecked)? UserRole.User : UserRole.Admin, Convert.ToBoolean(MaleRadioButton.IsChecked)? UserSex.Male : UserSex.Female); this.NavigationService.Navigate(new ListUsersPage()); } }
public async Task <ActionResult <bool> > isSubscribeOnEmailNotification(Guid userId) { UserServiceModel user = await _userService.GetByPrincipalAsync(User); if (user == null || user.Id != userId) { return(Unauthorized()); } bool isSubscribeOnEmailNotification = await _userService.IsSubscribeOnEmailNotificationAsync(user.Id); return(Ok(isSubscribeOnEmailNotification)); }
// // GET: /CuentaGasto/Edit/5 public ActionResult Edit(int id) { CuentaGastos cg = new CuentaGastos() { IdCuentaGastos = id }; UserServiceModel us = new UserServiceModel(); var lis = us.getUsersList(); SelectList lista = new SelectList(lis, "CodigoAcreditacion", "Nombre", 0); ViewBag.Lista = lista; return(View(cg.verCuentaGastos())); }
public async Task <IActionResult> UnsubscribeFromEmailNotification(Guid userId) { UserServiceModel user = await _userService.GetByPrincipalAsync(User); if (user == null || user.Id != userId) { return(Unauthorized()); } await _userService.UnsubscribeFromEmailNotificationAsync(user.Id); return(NoContent()); }
public async Task UpdateAsync(UserServiceModel entity) { if (entity == null) { return; } User user = _mapper.Map <UserServiceModel, User>(entity); _uow.GetRepository <User>().Update(user); await _uow.SaveChangesAsync(); }
private UserViewModel ConvertToUserViewModel(UserServiceModel model) { return(new UserViewModel { Id = model.User.Id, UserName = model.User.UserName, Email = model.User.Email, FirstName = model.User.FirstName, LastName = model.User.LastName, Telephone = model.User.Telephone, Role = model.Role }); }