private async Task SetProjectRoute(int routeId, int?projectId, ProjectRoute existingProjectRoute) { if (existingProjectRoute != null) { if (projectId.HasValue) { if (existingProjectRoute.ProjectId != projectId) { existingProjectRoute.ProjectId = projectId.Value; await _projectRouteRepository.UpdateAsync(existingProjectRoute); } } else { await _projectRouteRepository.DeleteByIdAsync(existingProjectRoute.Id); } } else if (projectId.HasValue) { var projectRoute = new ProjectRoute { RouteId = routeId, ProjectId = projectId.Value }; await _projectRouteRepository.AddAsync(projectRoute); } }
/// <summary> /// Initialize field _project. /// </summary> /// <param name="route">User name and project name</param> private async Task Init(ProjectRoute route) { var request = new HandlerData <ProjectRoute, Project> { Data = route }; _project = await _mediator.Send(request); }
public async Task <IActionResult> ChangeState([FromRoute] ProjectRoute route) { //Getting field _project based on route. await Init(route); var request = new HandlerData <Project, Unit> { Data = _project, }; await _mediator.Send(request); return(RedirectToAction(nameof(Show), route)); }
public async Task <IActionResult> Delete([FromRoute] ProjectRoute route) { //Getting field _project based on route. await Init(route); var request = new HandlerData <Project, ErrorResponce> { Data = _project }; await _mediator.Send(request); return(RedirectToRoute("Projects", new { userName = route.UserName })); }
public async Task <IActionResult> Show([FromRoute] ProjectRoute route) { //Getting field _project based on route. await Init(route); var request = new HandlerData <Project, Dictionary <ProjectSnapshotsTableRow, IEnumerable <string> > > { Data = _project }; Dictionary <ProjectSnapshotsTableRow, IEnumerable <string> > dataAndComments = await _mediator.Send(request); string [] snapshotNames = dataAndComments.Select(data => data.Key.Name).ToArray(); string [] snaspshotReferences = dataAndComments.Select(data => $"{HttpContext.Request.Path}/{data.Key.Name}") .ToArray(); // Creation table for project snapshots. var table = new ReferencedTable( new NumberedTable(new ObjectTable <ProjectSnapshotsTableRow>(dataAndComments .Select(data => data.Key).ToArray())), new Dictionary <string, string[]>() { { "Name", snaspshotReferences } } ); return(View("Project", new ProjectInfo { Name = _project.Name, IsActive = _project.isActive, SnapshotAddingLocation = HttpContext.Request.Path, StateLocation = $"{HttpContext.Request.Path}/state", FormData = new CommentAddingFormData { CommentLocation = $"{HttpContext.Request.Path}/comment", SnapshotChoice = new SelectList(snapshotNames) }, Data = new ProjectSnapshotsTableData { Table = table, Comments = dataAndComments.Select(data => data.Value).ToArray() } })); }
/// <summary> /// The initialize account modules or routes. /// </summary> /// <param name="handler"> /// The handler. /// </param> private void InitializeRoutes(AdminRequestHandler handler) { User = new UserRoute(handler); Survey = new SurveyRoute(handler); Project = new ProjectRoute(handler); Email = new EmailRoute(handler); Common = new CommonRoute(handler); Questionnaire = new QuestionnaireRoute(handler); Media = new MediaRoute(handler); Panel = new PanelRoute(handler); Panellist = new PanellistRoute(handler); ProfileElement = new ProfileElementRoute(handler); GeoLocation = new GeoLocationRoute(handler); GeoFence = new GeoFencingRoute(handler); Sample = new SampleRoute(handler); Theme = new ThemeRoute(handler); Scheduler = new SchedulerRoute(handler); Notification = new NotificationRoute(handler); }
public async Task <IActionResult> Comment([FromForm] CommentFormData formData, [FromRoute] ProjectRoute route) { if (ModelState.IsValid) { //Getting field _project based on route. await Init(route); var request = new ProjectHandlerData <(string UserName, CommentFormData FormData), ErrorResponce> { Data = (User.Identity.Name, formData), Project = _project, }; // Getting object that contain errors about login user data. ErrorResponce responce = await _mediator.Send(request); // Checking errors if exist then add them to modelstate. ModelState.CheckErrors(responce); } return(RedirectToAction(nameof(Show), route)); }