// GET: MovieLists
        public IActionResult Index()
        {
            var applicationContext = _movieset.GetAll()
                                     .Where(x => x.UserID == _currentuserid.GetCurrentUserId(_httpContextAccessor));

            return(View(applicationContext.ToList()));
        }
Esempio n. 2
0
        public async Task <ActionResult <UserDto> > Get()
        {
            long userId = _currentUserService.GetCurrentUserId();
            var  user   = await _userService.Get(userId);

            if (user == null)
            {
                return(NotFound());
            }
            return(_mapper.Map <UserDto>(user));
        }
Esempio n. 3
0
        public void UpdateModifiedByModifiedDate(ModificationInfo entity)
        {
            var userId = _currentUserService.GetCurrentUserId();

            entity.ModifiedBy       = userId;
            entity.ModificationDate = DateTime.Now;
        }
        public async Task <List <DashboardDto> > Handle(GetFavoriteDashboardsQuery request, CancellationToken cancellationToken)
        {
            var currentUserId = currentUserService.GetCurrentUserId();

            var applicationDashboards = await(from app in context.Applications
                                              join dashboard in context.Dashboards
                                              on app.Id equals dashboard.ApplicationId
                                              where app.UserId == currentUserId && dashboard.IsFavorite
                                              select dashboard)
                                        .AsNoTracking()
                                        .ToListAsync();

            var result = new List <DashboardDto>();

            foreach (var item in applicationDashboards)
            {
                result.Add(new DashboardDto
                {
                    ApplicationId = item.ApplicationId,
                    Id            = item.Id,
                    CreatedDate   = item.CreatedDate,
                    Name          = item.Name,
                    IsFavorite    = item.IsFavorite
                });
            }

            return(mapper.Map <List <DashboardDto> >(applicationDashboards));
        }
Esempio n. 5
0
        public async Task <Guid> Handle(CreateWidgetCommand request, CancellationToken cancellationToken)
        {
            var currentUserId = currentUserService.GetCurrentUserId();

            var application = await context.Applications
                              .FirstOrDefaultAsync(app => app.Id == request.ApplicationId && app.UserId == currentUserId);

            if (application == null)
            {
                throw new EntityNotFoundException(nameof(Application), request.ApplicationId);
            }

            var widgetHandlerFactory = new WidgetsHandlerFactory();
            var widgetHandler        = widgetHandlerFactory.Make(request.WidgetType);

            var widget = new Widget(request.Name, application.Id)
            {
                Type = request.WidgetType.ToString(),
                Data = widgetHandler.GetDefaultJson()
            };

            await context.Widgets.AddAsync(widget);

            await context.SaveChangesAsync();

            return(widget.Id);
        }
Esempio n. 6
0
        public async Task <List <WidgetDetailsVm <T> > > Handle(GetWidgetsQuery <T> request, CancellationToken cancellationToken)
        {
            var currentUserId = currentUserService.GetCurrentUserId();

            var dbWidgets = await(from application in context.Applications
                                  join widget in context.Widgets
                                  on application.Id equals widget.ApplicationId
                                  where request.WidgetsIds.Contains(widget.Id) && application.UserId == currentUserId
                                  select widget)
                            .AsNoTracking()
                            .ToListAsync();


            var widgetHandlerFactory = new WidgetsHandlerFactory();
            var result = new List <WidgetDetailsVm <T> >();

            foreach (var dbWidget in dbWidgets)
            {
                var widgetHandler = widgetHandlerFactory.Make(dbWidget.Type);

                var widgetData = new WidgetDetailsVm <T>
                {
                    WidgetData = (T)widgetHandler.FromJson(dbWidget.Data),
                    Widget     = mapper.Map <WidgetDto>(dbWidget)
                };

                result.Add(widgetData);
            }

            return(result);
        }
Esempio n. 7
0
        public async Task <Unit> Handle(UpdateWidgetCommand <T> request, CancellationToken cancellationToken)
        {
            var currentUserId = currentUserService.GetCurrentUserId();

            var dbWidget = await(from widget in context.Widgets
                                 join application in context.Applications
                                 on widget.ApplicationId equals application.Id
                                 where widget.Id == request.Id && application.UserId == currentUserId
                                 select widget).FirstOrDefaultAsync();

            if (dbWidget == null)
            {
                throw new EntityNotFoundException(nameof(Widget), request.Id);
            }

            var widgetHandlerFactory = new WidgetsHandlerFactory();
            var widgetHandler        = widgetHandlerFactory.Make(dbWidget.Type);

            dbWidget.Name = request.Name;
            dbWidget.Data = widgetHandler.GetJson(request.WidgetData);

            context.Widgets.Update(dbWidget);
            await context.SaveChangesAsync();

            return(Unit.Value);
        }
        public JsonResult ApplyForTournament(GroupTeamViewModel groupTeam)
        {
            JsonResult result = null;

            try
            {
                var userId = _currentUserService.GetCurrentUserId();

                if (userId == ANONYM)
                {
                    result = Json(ViewModelResources.NoRights);
                }
                else
                {
                    var tournamentRequest = new TournamentRequest {
                        TeamId  = groupTeam.TeamId,
                        UserId  = userId,
                        GroupId = groupTeam.GroupId
                    };
                    _requestService.Create(tournamentRequest);
                    result = Json(ViewModelResources.SuccessRequest);
                }
            }
            catch (ArgumentException ex)
            {
                result = Json(ex.Message);
            }

            return(result);
        }
Esempio n. 9
0
        public async Task <Guid> Handle(EditQuestionCommand request, CancellationToken cancellationToken)
        {
            var employerId = _currentUserService.GetCurrentUserId();
            var question   = await _store.Questions.Where(x => x.EmployerId == employerId).WithIdAsync(request.Id);

            var questionOptions = await _store.Options.Where(x => x.QuestionId == question.Id).ToListAsync();

            await _store.DeleteEntitiesAsync(questionOptions);

            question.Text        = request.Text;
            question.QuestionTag = request.QuestionTag;

            var options = _mapper.Map <List <Option> >(request.Options);

            foreach (var option in options)
            {
                option.QuestionId = question.Id;
            }

            await _store.AddEntitiesAsync(options);

            await _store.SaveChangesAsync();

            return(request.Id);
        }
Esempio n. 10
0
        public async Task <bool> Handle(FavoriteDashboardCommand request, CancellationToken cancellationToken)
        {
            var currentUserId = currentUserService.GetCurrentUserId();

            var dbDashboard = await(from application in context.Applications
                                    join dashboard in context.Dashboards
                                    on application.Id equals dashboard.ApplicationId
                                    where dashboard.Id == request.DashboardId && application.UserId == currentUserId
                                    select dashboard)
                              .Include(x => x.DashboardWidgets)
                              .ThenInclude(dw => dw.Widget)
                              .FirstOrDefaultAsync();

            if (dbDashboard == null)
            {
                throw new EntityNotFoundException(nameof(Dashboard), request.DashboardId);
            }

            dbDashboard.IsFavorite = request.IsFavorite;

            context.Update(dbDashboard);
            await context.SaveChangesAsync();

            return(dbDashboard.IsFavorite);
        }
        public async Task <Guid> Handle(CreateApplicationCommand request, CancellationToken cancellationToken)
        {
            var currentUserId = currentUserService.GetCurrentUserId();
            var application   = await createApplicationService.CreateAsync(request.ApplicationName, currentUserId);

            return(application.Id);
        }
        public async Task <short> Handle(AddTestResultCommand request, CancellationToken cancellationToken)
        {
            var  selectedVacancy = _store.Vacancies.FirstOrDefault(v => v.Id == request.VacancyId);
            Guid studentId       = _currentUserService.GetCurrentUserId();

            if (selectedVacancy == null)
            {
                throw new Exception("Vacancy doe not exist.");
            }

            var questionIds = request.Answers.Select(ans => ans.Id).ToList();

            var questionOptionDict = await _store.Questions
                                     .Include(q => q.Options)
                                     .Where(q => questionIds.Contains(q.Id))
                                     .Select(q => new KeyValuePair <Guid, List <Guid> >
                                             (
                                                 q.Id,
                                                 q.Options.Where(op => op.IsCorrect).Select(op => op.Id).ToList()
                                             ))
                                     .ToDictionaryAsync(x => x.Key, x => x.Value);

            int correctOptionCount      = questionOptionDict.Sum(q => q.Value.Count());
            int correctUserAnswersCount = request
                                          .Answers.Sum(ans => ans.ChoosedOptions.Intersect(questionOptionDict[ans.Id]).Count());

            short score = (short)Math.Round(((double)correctUserAnswersCount / correctOptionCount) * 100.0, 0);


            short priority = (short)(_store.StudentVacancies
                                     .Where(x => x.StudentId == studentId && x.Vacancy.CampaignId == selectedVacancy.CampaignId)
                                     .Count() + 1);

            var newStudentVacancy = new StudentVacancy
            {
                StudentId = _currentUserService.GetCurrentUserId(),
                VacancyId = request.VacancyId,
                Score     = score,
                Priority  = priority
            };

            await _store.AddEntityAsync(newStudentVacancy);

            await _store.SaveChangesAsync();

            return(score);
        }
        public async Task <IEnumerable <BillDto> > GetBillsAsync(int pageSize, int pageIndex)
        {
            Guid currentUserId = currentUserService.GetCurrentUserId();

            var result = await this.sender.Send(new SearchBillsQuery(currentUserId, pageSize, pageIndex));

            return(result.Value);
        }
        private ICollection <AuthOperation> GetAllUserOperations()
        {
            var userId = _userService.GetCurrentUserId();

            return(_getOperationsQuery.Execute(new FindByUserIdCriteria {
                UserId = userId
            }));
        }
Esempio n. 15
0
        public async Task <PagedResult <QuestionViewModel> > Handle(GetEmployerQuestionQuery request, CancellationToken cancellationToken)
        {
            var employerId = _currentUserService.GetCurrentUserId();

            return(await _store.Questions
                   .Where(x => x.EmployerId == employerId)
                   .ApplyQueryAsync <Question, QuestionViewModel>(request, _mapper.ConfigurationProvider));
        }
Esempio n. 16
0
        public override async Task <ActionResult <Project> > Post([FromBody] Project item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Blad walidacji"));
            }

            var userId = _currentUserService.GetCurrentUserId();

            ModificationService.UpdateModifiedByModifiedDate(item);
            var project = await _projectService.CreateNewProject(userId, item);

            return(Ok(project));
        }
        public async Task <PagedResult <CampaignViewModel> > Handle(GetAdminCampaignsQuery request, CancellationToken cancellationToken)
        {
            var adminId = _currentUserService.GetCurrentUserId();

            return(await _store.Campaigns
                   .AsNoTracking()
                   .Where(x => x.AdminId == adminId)
                   .ApplyQueryAsync <Campaign, CampaignViewModel>(request, _mapper.ConfigurationProvider));
        }
        public async Task Process(TRequest request, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Received request: Type: {typeof(TRequest).Name} Request: {request}");

            var requestName = typeof(TRequest).Name;
            var userId      = _currentUserService.GetCurrentUserId();
            var userName    = await _identityService.GetUserNameFromIdAsync(userId);

            _logger.LogInformation($"Received request: Type: {typeof(TRequest).Name} Request: {request} UserId: {userId} UserName: {userName}");
        }
        public async Task <List <ApplicationDto> > Handle(ListApplicationsQuery request, CancellationToken cancellationToken)
        {
            var currentUserId = currentUserService.GetCurrentUserId();

            var applications = await context.Applications
                               .Where(a => a.UserId == currentUserId)
                               .AsNoTracking()
                               .ToListAsync();

            return(mapper.Map <List <ApplicationDto> >(applications));
        }
        public async Task Process(TRequest request, CancellationToken cancellationToken)
        {
            var requestName = typeof(TRequest).Name;

            var currentUser = await _identityService.GetCurrentUser();

            var currentUserId = _currentUserService.GetCurrentUserId();

            _logger.LogInformation("CleanTesting Request: {Name} {@UserId} {@UserName} {@Request}",
                                   requestName, currentUserId, currentUser.UserName, request);
        }
Esempio n. 21
0
        //public DbSet<ModTitle> ModTitles { get; set; }
        //public DbSet<Dependency> Dependencies { get; set; }
        //public DbSet<DependencyType> DependencyTypes { get; set; }
        //public DbSet<DependencyComparisonType> DependencyComparisonTypes { get; set; }

        public override async Task <int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
        {
            foreach (var entry in ChangeTracker.Entries <AuditableEntity>())
            {
                // TODO: I'm not a fan of the fact that our EF code is responsible for setting these, rather than a default value or a database trigger.
                switch (entry.State)
                {
                case EntityState.Added:
                    entry.Entity.AddedBy   = _currentUserService.GetCurrentUserId();
                    entry.Entity.AddedDate = _dateTimeService.GetCurrentTime();
                    break;

                case EntityState.Modified:
                    entry.Entity.LastModifiedBy = _currentUserService.GetCurrentUserId();
                    entry.Entity.LastModified   = _dateTimeService.GetCurrentTime();
                    break;
                }
            }

            return(await base.SaveChangesAsync(cancellationToken));
        }
        public async Task <PagedResult <VacancyViewModel> > Handle(GetEmployerVacanciesQuery request, CancellationToken cancellationToken)
        {
            var employerId = _currentUserService.GetCurrentUserId();

            var vacancies = await _store.Vacancies
                            .Include(x => x.Campaign)
                            .Include(x => x.Employer)
                            .Where(x => x.EmployerId == employerId)
                            .ApplyQueryAsync <Vacancy, VacancyViewModel>(request, _mapper.ConfigurationProvider);

            return(vacancies);
        }
        public async Task <List <string> > Handle(GetQuestionTagsQuery request, CancellationToken cancellationToken)
        {
            var employerId = _currentUserService.GetCurrentUserId();

            var employerTags = await _store.Questions
                               .Where(x => x.EmployerId == employerId)
                               .Select(x => x.QuestionTag)
                               .ToListAsync();

            employerTags.AddRange(_defaultTags);
            return(employerTags.Distinct().ToList());
        }
Esempio n. 24
0
        public bool CheckUserId(int?id, IHttpContextAccessor httpContextAccessor)
        {
            if (id == null)
            {
                throw new ArgumentNullException("Null");
            }

            var userid = currentUserService.GetCurrentUserId(httpContextAccessor);

            MovieSet movieSet = repoMovieSet.GetSingle(id);

            return(userid.Equals(movieSet.UserID));
        }
        public async Task <Guid> Handle(CreateVacancyCommand request, CancellationToken cancellationToken)
        {
            var vacancy    = _mapper.Map <Vacancy>(request);
            var employerId = _currentUserService.GetCurrentUserId();

            vacancy.DateCreated = DateTime.Now;

            vacancy.EmployerId = employerId;

            await _store.AddEntityAsync(vacancy, saveChanges : true);

            return(vacancy.Id);
        }
Esempio n. 26
0
        /// <summary>
        /// Gets current user mail.
        /// </summary>
        /// <returns>User email.</returns>
        private string GetUserMail()
        {
            var userId      = _currentUserService.GetCurrentUserId();
            var currentUser = new User {
                Email = string.Empty
            };

            if (userId != ANONYM)
            {
                currentUser = _userService.GetUser(userId);
            }

            return(currentUser.Email);
        }
        /// <summary>
        /// Change status of the feedback
        /// </summary>
        /// <param name="feedback">id for reply.</param>
        /// <param name="newStatusCode">Information about mail (body, receiver)</param>
        private void ChangeFeedbackStatus(Feedback feedback, FeedbackStatusEnum newStatusCode)
        {
            feedback.Status = newStatusCode;
            if (ShouldChangeLastUpdateInfo(newStatusCode))
            {
                int  userId = _currentUserService.GetCurrentUserId();
                User user   = _userService.GetUser(userId);
                feedback.UpdateDate = TimeProvider.Current.UtcNow;
                feedback.AdminName  = user.PersonName;
            }

            _feedbackRepository.Update(feedback);
            _feedbackRepository.UnitOfWork.Commit();
        }
        public async Task <Guid> Handle(CreateCampaignCommand request, CancellationToken cancellationToken)
        {
            var campaign = new Campaign()
            {
                Name      = request.Name,
                StartDate = request.StartDate,
                EndDate   = request.EndDate,
                AdminId   = _currentUserService.GetCurrentUserId()
            };

            var addedEntity = await _store.AddEntityAsync(campaign, saveChanges : true);

            return(addedEntity.Id);
        }
        public async Task<Unit> Handle(UpdateDashboardCommand request, CancellationToken cancellationToken)
        {
            var currentUserId = currentUserService.GetCurrentUserId();

            var dbDashboard = await GetDashboard(request.DashboardId, request.ApplicationId, currentUserId);

            if (dbDashboard == null)
                throw new EntityNotFoundException(nameof(Dashboard), request.DashboardId);

            // Validate and remove the Widgets that don't belong to this dashboard
            request.DashboardWidgets = await ValidateWidgets(request.DashboardWidgets, request.ApplicationId);

            // Remove DashboardWidgets that are not present (removed)
            dbDashboard.DashboardWidgets = dbDashboard.DashboardWidgets
                .Where(oldWidget => request.DashboardWidgets.Exists(newWidget => newWidget.Id == oldWidget.Id)).ToList();

            foreach (var dashboardWidget in request.DashboardWidgets)
            {
                if (dashboardWidget.Id == null || !dbDashboard.DashboardWidgets.Exists(x => x.Id == dashboardWidget.Id))
                {
                    // Insert DashboardWidget
                    dbDashboard.DashboardWidgets.Add(new DashboardWidget
                    {
                        Height = dashboardWidget.Height,
                        Width = dashboardWidget.Width,
                        X = dashboardWidget.X,
                        Y = dashboardWidget.Y,
                        WidgetId = dashboardWidget.WidgetId,
                        DashboardId = dbDashboard.Id,
                    });
                }
                else
                {
                    // Update DashboardWidget
                    var dbWidget = dbDashboard.DashboardWidgets.FirstOrDefault(x => x.Id == dashboardWidget.Id);
                    dbWidget.Height = dashboardWidget.Height;
                    dbWidget.Width = dashboardWidget.Width;
                    dbWidget.X = dashboardWidget.X;
                    dbWidget.Y = dashboardWidget.Y;
                }
            }

            context.Dashboards.Update(dbDashboard);

            await context.SaveChangesAsync();

            return Unit.Value;
        }
        public async Task <List <WidgetDto> > Handle(GetWidgetForApplicationQuery request, CancellationToken cancellationToken)
        {
            var currentUserId = currentUserService.GetCurrentUserId();

            var application = await context.Applications
                              .Where(application => application.Id == request.ApplicationId && application.UserId == currentUserId)
                              .Include(application => application.Widgets)
                              .FirstOrDefaultAsync();

            if (application == null)
            {
                throw new EntityNotFoundException(nameof(Application), request.ApplicationId);
            }

            return(mapper.Map <List <WidgetDto> >(application.Widgets));
        }