public async Task <WorkProgressResponseDTO> addWorkProgress(int todoId, WorkProgressRequestDTO dto) { var entity = await TodoRepository.getDetailsById(todoId); if (entity == null) { return(null); } var wprgEntity = ControllerMapper.Map <WorkProgressRequestDTO, WorkProgressEntity>(dto); wprgEntity.Person = await UserRepository.getById(dto.Person); var createdEntity = await WorkProgressRepository.add(wprgEntity); if (createdEntity == null) { return(null); } entity.WorkProgressEntities.Add(createdEntity); await Repo.update(entity); return(ControllerMapper.Map <WorkProgressEntity, WorkProgressResponseDTO>(createdEntity)); }
public override async ValueTask <RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } if (values == null) { throw new ArgumentNullException(nameof(values)); } var startPage = httpContext.Items[RoutingKeys.StartPage] as IStartPage;//стартовая страница, проставляется в RoutingMiddleware if (startPage == null) { return(values); } var targetingFilter = TargetingFilterAccessor?.Get();//все зарегистрированные фильтры структуры сайта, объединенные в один //вычислим PathData текущего запроса - какая страница в структуре сайта должна быть активирована, //разбирая урл запроса, и сопоставляя сегменты со структурой сайта var path = httpContext.Request.Path; PathData data = CreatePathFinder().Find(path, startPage, targetingFilter, HeadUrlResolver); if (data == null) { return(values); } //вычислим какой контроллер должен вызываться var controllerName = ControllerMapper.Map(data.AbstractItem); if (string.IsNullOrEmpty(controllerName)) { return(values); } //вычислим остальные route values из хвоста урла var routeValues = TailUrlResolver.ResolveRouteValues(data.RemainingUrl, controllerName); if (!routeValues.Any()) { //не удалось определить из хвоста урла никаких route values return(values); } values["controller"] = controllerName; values[RoutingKeys.CurrentItem] = data.AbstractItem; foreach (var rvKey in routeValues.Keys) { values[rvKey] = routeValues[rvKey]; } return(values); }
public async Task <ResponseDTO <UserResponseDTO> > getByEMail(string email) { var userEntity = await UserRepo.getByEmail(email); if (userEntity == null) { return(new ResponseDTO <UserResponseDTO>("Given user E-Mail not found")); } return(new ResponseDTO <UserResponseDTO>(ControllerMapper.Map <UserEntity, UserResponseDTO>(userEntity))); }
public async Task <List <TodoDTO> > getAssignedTodos(int id) { var entity = await ProjectRepository.getDetailsById(id); if (entity?.Todos == null) { return(new List <TodoDTO>()); } return(ControllerMapper.Map <List <TodoEntity>, List <TodoDTO> >(entity.Todos.ToList())); }
public override async Task <ResponseDTO <ProjectResponseDTO> > add(ProjectRequestDTO dto) { var entity = ControllerMapper.Map <ProjectRequestDTO, ProjectEntity>(dto); entity.Owner = await UserRepository.getById(dto.Owner); var createdEntity = await Repo.add(entity); return(new ResponseDTO <ProjectResponseDTO>(ControllerMapper.Map <ProjectEntity, ProjectResponseDTO>(createdEntity))); }
public async Task <List <UserResponseDTO> > getAssignedUsers(int todoId) { var entity = await TodoRepository.getDetailsById(todoId); if (entity?.TodoUserAssignments == null) { return(new List <UserResponseDTO>()); } List <UserEntity> assignedUsers = new List <UserEntity>(); foreach (var assignment in entity.TodoUserAssignments.ToList()) { assignedUsers.Add(await UserRepository.getById(assignment.UserId)); } return(ControllerMapper.Map <List <UserEntity>, List <UserResponseDTO> >(assignedUsers)); }
public async Task <List <WorkProgressResponseDTO> > getWorkProgress(int todoId) { var entity = await TodoRepository.getDetailsById(todoId); if (entity == null) { return(new List <WorkProgressResponseDTO>(todoId)); } List <WorkProgressEntity> workProgressEntities = new List <WorkProgressEntity>(); foreach (var we in entity.WorkProgressEntities) { workProgressEntities.Add(await WorkProgressRepository.getById(we.Id)); } return(ControllerMapper.Map <List <WorkProgressEntity>, List <WorkProgressResponseDTO> >(workProgressEntities)); }
public override async Task <ResponseDTO <UserResponseDTO> > add(UserRequestDTO userRequestDto) { var userEntity = await Task.Run(() => { return(ControllerMapper.Map <UserRequestDTO, UserEntity>(userRequestDto, opt => { opt.AfterMap((dto, entity) => { byte[] generatedSalt = PasswordManager.GenerateSalt(); entity.Salt = Convert.ToBase64String(generatedSalt); entity.Password = PasswordManager.GeneratePasswordHash(generatedSalt, dto.Password); }); })); }); var newUserEntity = await Repo.add(userEntity); return(new ResponseDTO <UserResponseDTO>(ControllerMapper.Map <UserEntity, UserResponseDTO>(newUserEntity))); }
public async Task <TodoDTO> createAndAssignTodo(int projectId, TodoDTO todo) { var entity = await ProjectRepository.getDetailsById(projectId); if (entity == null) { return(null); } var createdTodo = await TodoRepository.add(ControllerMapper.Map <TodoDTO, TodoEntity>(todo)); if (createdTodo == null) { return(null); } entity.Todos.Add(createdTodo); await Repo.update(entity); return(ControllerMapper.Map <TodoEntity, TodoDTO>(createdTodo)); }
public async Task <List <UserResponseDTO> > getAssignedUsers(int projectId) { var entity = await ProjectRepository.getDetailsById(projectId); if (entity == null) { return(new List <UserResponseDTO>()); } if (entity.ProjectUserAssignments == null || entity.ProjectUserAssignments.Count < 1) { return(new List <UserResponseDTO>()); } var userAssignments = entity.ProjectUserAssignments.ToList(); List <UserEntity> assignedUsers = new List <UserEntity>(); foreach (var assignment in userAssignments) { assignedUsers.Add(await UserRepository.getById(assignment.UserId)); } return(ControllerMapper.Map <List <UserEntity>, List <UserResponseDTO> >(assignedUsers)); }
protected override PathFinder CreatePathFinder() { //добавляем условие остановки в траверс структуры сайта: когда доходим до страницы, которой соответствует контроллер, переданный в Defaults return(new PathFinder(ai => Defaults.ContainsKey("controller") ? Defaults["controller"].ToString() == ControllerMapper.Map(ai) : false)); }