public override void Process(PasswordResetViewModel viewModel) { var user = userProvider.GetUserByEmail(viewModel.Email); if (user.IsNullOrDefault()) { return; } var reloadedViewModel = reloader.Reload(viewModel); var subject = translationManager.GetTranslationLabel(LanguageId, "Dashboard:Admin:MailSubject"); using (var transaction = new TransactionScope(TransactionScopeOption.Required)) { user.ResetToken = RandomToken(); user.ResetTokenDate = DateTime.Now; userService.AddOrUpdate(user); reloadedViewModel.Firstname = user.Firstname; reloadedViewModel.RootUrl = GetRootUrl(); reloadedViewModel.Token = user.ResetToken; var mailHTML = CreateResetMail(reloadedViewModel).Result; mailQueueService.AddNew( user.Email, subject, mailHTML); transaction.Complete(); } }
public async Task <Skill> AddOrUpdate(SkillDto entry) { var skill = _mapper.Map <SkillDto, Skill>(entry); _service.AddOrUpdate(skill); await _unitOfWok.CommitAsync(); return(skill); }
public override void Process(ResetPasswordViewModel viewModel) { var user = userProvider.GetUserByToken(viewModel.Token); if (user.IsNullOrDefault() || !user.ResetTokenDate.HasValue || user.ResetTokenDate.Value.AddHours(12) < DateTime.Now) { return; } user.Password = PBFDF2Hash.Hash(viewModel.Password); user.ResetToken = string.Empty; user.ResetTokenDate = null; userService.AddOrUpdate(user); }
public void AddOrUpdate(BlogResponseModel entry) { _Service.AddOrUpdate(_Mapper.Map <BlogResponseModel, DAL.Models.Blog>(entry)); }
public override void Process(UserViewModel viewModel) { var currentUserPermissions = permissionProvider .GetPermissions(UserId) .Select(x => x.Action) .ToList(); var user = userProvider.GetEntity(x => x.Id == viewModel.Id); var roles = roleProvider.GetAllAsList(); using (var transaction = new TransactionScope(TransactionScopeOption.Required)) { if (user.IsNullOrDefault()) { if (!currentUserPermissions.Contains(Permissions.GetActionKey(Module.Dashboard, Type.User, Action.Edit))) { return; } user = new User { Email = viewModel.Email, Password = string.Empty, Firstname = viewModel.Firstname, Lastname = viewModel.Lastname, ResetToken = string.Empty, ResetTokenDate = null, Active = viewModel.Active }; userService.Add(user); } else { user.Firstname = viewModel.Firstname; user.Lastname = viewModel.Lastname; if (currentUserPermissions.Contains(Permissions.GetActionKey(Module.Dashboard, Type.User, Action.Edit))) { user.Email = viewModel.Email; user.Active = viewModel.Active; } userService.AddOrUpdate(user); var currentUserRoles = userRoleProvider.Where(x => x.User_Id == user.Id); userRoleService.DeleteRange(currentUserRoles); } var selectedRoles = viewModel.Roles.Where(x => x.Active); var userRoles = roles.Where(x => selectedRoles.Any(y => y.Id == x.Id)) .Select(role => new UserRole { User_Id = user.Id, User = user, Role_Id = role.Id, Role = role }).ToList(); userRoleService.AddRange(userRoles); transaction.Complete(); } }
public void AddOrUpdate(DeviceModel model) { _deviceModelService.AddOrUpdate(_mapper.Map <DeviceModelData>(model)); _deviceModelService.Save(); }
public void AddOrUpdate(PacienteViewModel model) { _service.AddOrUpdate(_mapper.Map <PacienteViewModel, Paciente>(model)); }
public void AddOrUpdate(CourseResponseModel entry) { _service.AddOrUpdate(_mapper.Map <CourseResponseModel, Course>(entry)); }
public override void Process(RoleViewModel viewModel) { if (viewModel.Permissions.IsNullOrDefault() || viewModel.Permissions.Count == default(int)) { viewModel.Permissions = new List <PermissionViewModel>(); } var permissions = permissionProvider.GetAllAsList(); var role = roleProvider.GetEntity(r => r.Id == viewModel.Id); IEnumerable <PermissionViewModel> selectedViewModelPermissions; List <Permission> selectedPermissions; if (role.IsNullOrDefault()) { role = new Role { Name = viewModel.Name, Active = viewModel.Active }; selectedViewModelPermissions = viewModel.Permissions.Where(x => x.Active); selectedPermissions = permissions .Where(x => selectedViewModelPermissions.Any(y => y.Id == x.Id)) .ToList(); roleService.Add(role); if (!selectedPermissions.Any()) { return; } var rolePermissions = selectedPermissions.Select(x => new RolePermission { Role = role, Role_Id = role.Id, Permission_Id = x.Id, Permission = x }).ToList(); rolePermissionService.AddRange(rolePermissions); return; } var currentPermissions = rolePermissionProvider.Where(x => x.Role_Id == role.Id); selectedViewModelPermissions = viewModel.Permissions.Where(x => x.Active); selectedPermissions = permissions .Where(x => selectedViewModelPermissions.Any(y => y.Id == x.Id)) .ToList(); var deletedRoles = currentPermissions .Where(x => !selectedPermissions.Any(y => y.Id == x.Permission_Id)) .ToList(); var newRoles = selectedPermissions .Where(x => !currentPermissions.Any(y => x.Id == y.Permission_Id)) .Select(x => new RolePermission { Role = role, Role_Id = role.Id, Permission = x, Permission_Id = x.Id }).ToList(); role.Name = viewModel.Name; role.Active = viewModel.Active; roleService.AddOrUpdate(role); if (deletedRoles.Any()) { rolePermissionService.DeleteRange(deletedRoles); } if (newRoles.Any()) { rolePermissionService.AddRange(newRoles); } }
public void AddOrUpdate(Classification classification) { _classificationService.AddOrUpdate(_mapper.Map <ClassificationData>(classification)); _classificationService.Save(); }
public void AddOrUpdate(DetailedStatus status) { _detailedStatusService.AddOrUpdate(_mapper.Map <DetailedStatusData>(status)); _detailedStatusService.Save(); }
public void AddOrUpdate(DeviceEvent deviceEvent) { deviceEvent.Location = null; deviceEvent.Status = null; _deviceEventService.AddOrUpdate(_mapper.Map <DeviceEventData>(deviceEvent)); }