Ejemplo n.º 1
0
 public ResultsForm(Contest contest)
 {
     InitializeComponent();
     this._contest = contest;
     ShowResults(this._contest);
     this.Text = String.Format("Results by {0}", this._contest.Title);
 }
Ejemplo n.º 2
0
 public AddContestForm(Contest contest = null)
 {
     InitializeComponent();
     db = new DatabaseEntities();
     _contest = contest;
     FillFields();
 }
Ejemplo n.º 3
0
 public ClientContestForm(User user, Contest contest)
 {
     InitializeComponent();
     this._user = user;
     this._contest = contest;
     MakeTabs();
 }
Ejemplo n.º 4
0
 public ManageContest(Contest contest)
 {
     InitializeComponent();
     this._contest = contest;
     this.Text = String.Format("{0}: {1}", this.Text, contest.Title);
     ShowTasks();
     ShowUsers();
     labelStartTime.Text = this._contest.StartTime.ToString();
     labelEndTime.Text = this._contest.EndTime.ToString();
     labelTitle.Text = this._contest.Title;
 }
Ejemplo n.º 5
0
 public AddTaskForm(Contest contest, Task task = null)
 {
     InitializeComponent();
     db = new DatabaseEntities();
     this._contest = contest;
     this._task = task;
     if (this._task != null)
     {
         textBoxTitle.Text = this._task.Title;
         richTextBoxDescription.Text = this._task.Description;
         textBoxMark.Text = this._task.Mark.ToString();
     }
 }
Ejemplo n.º 6
0
        private void ShowResults(Contest contest)
        {
            using (var db = new DatabaseEntities())
            {
                var tasks = db.Tasks.Where(t => t.ContestId == this._contest.Id);
                if (tasks == null)
                {
                    MessageBox.Show("There are no result by this contest.");
                    return;
                }
                var Tasks = tasks.Select(t => t.Id).ToList();
                var tests = db.Tests.Where(t => Tasks.Contains(t.TaskId)).Select(t=>t.Id).ToList();

                var results = db.Results.Where(t => tests.Contains(t.TaskId)).ToList();

                foreach (var item in results)
                {

                }

            }
        }
Ejemplo n.º 7
0
        public ActionResult Create(ContestBindingModel model)
        {
            if (this.ModelState != null && this.ModelState.IsValid)
            {
                Category category = this.ContestsData.Categories.Find(model.Category);
                bool isModelValid = CustomValidators.IsContestModelValid(category, model);
                if (!isModelValid)
                {
                    this.AddToastMessage("Error", "Invalid data.", ToastType.Error);
                    return View(model);
                }

                ICollection<User> voters = model.VotingType == VotingType.Closed ? this.GetUsers(model.Voters) : new HashSet<User>();
                ICollection<User> participants = model.ParticipationType == ParticipationType.Closed ? this.GetUsers(model.Participants) : new HashSet<User>();

                var contest = new Contest
                {
                    Title = model.Title,
                    Description = model.Description,
                    OrganizatorId = this.UserProfile.Id,
                    RewardType = model.RewardType,
                    DeadlineType = model.DeadlineType,
                    ParticipationType = model.ParticipationType,
                    VotingType = model.VotingType,
                    Voters = voters,
                    WinnersCount = model.WinnersNumber,
                    ParticipantsNumberDeadline = model.ParticipantsNumberDeadline,
                    Participants = participants,
                    DeadLine = model.DeadLine,
                    CategoryId = model.Category
                };

                if (model.Upload != null && model.Upload.ContentLength > 0)
                {
                    var wallpaperPaths = Helpers.UploadImages.UploadImage(model.Upload, true);
                    var wallpaperUrl = Dropbox.Download(wallpaperPaths[0]);
                    var wallpaperThumbUrl = Dropbox.Download(wallpaperPaths[1], "Thumbnails");

                    contest.WallpaperPath = wallpaperPaths[0];
                    contest.WallpaperUrl = wallpaperUrl;
                    contest.WallpaperThumbPath = wallpaperPaths[1];
                    contest.WallpaperThumbUrl = wallpaperThumbUrl;
                }
                else
                {
                    contest.WallpaperUrl = AppKeys.WallpaperUrl;
                }

                this.ContestsData.Contests.Add(contest);
                this.ContestsData.SaveChanges();
                this.AddToastMessage("Success", "Contest created.", ToastType.Success);
                return this.RedirectToAction("Details", "Users", routeValues: new { id = this.UserProfile.Id, area = "" });
            }

            return this.View();
        }
Ejemplo n.º 8
0
        private void SendParticipantsNotification(Contest contest)
        {
            var hubContext = GlobalHost.ConnectionManager.GetHubContext<NotificationsHub>();

            var participants = contest.Photos.GroupBy(f => f.OwnerId);

            foreach (var participant in participants)
            {
                var notification = new Notification
                {
                    UserId = participant.Key,
                    Message = string.Format("A contest you participated in was finalized. See contest result <a href=\"Winners/Details/{0}\">here</a>", contest.Id),
                    Date = DateTime.Now,
                    IsRead = false
                };

                this.ContestsData.Notifications.Add(notification);
                hubContext.Clients.Group(participant.Key).receiveNotification();
            }

            this.ContestsData.SaveChanges();
        }
Ejemplo n.º 9
0
        private void FillVoters(Contest contest, ICollection<string> votersIds, VotingType votingType)
        {
            if (votersIds == null || votingType == VotingType.Open)
            {
                contest.Voters.Clear();
            }
            else
            {
                var voters = contest.Voters.ToList();

                foreach (var voterId in votersIds)
                {
                    if (contest.Voters.All(v => v.Id != voterId))
                    {
                        var voter = this.ContestsData.Users.Find(voterId);
                        contest.Voters.Add(voter);
                    }
                }

                foreach (var voter in voters)
                {
                    if (!votersIds.Contains(voter.Id))
                    {
                        contest.Voters.Remove(voter);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        private void FillPacticipants(Contest contest, ICollection<string> participantsIds, ParticipationType participationType)
        {
            if (participantsIds == null || participationType == ParticipationType.Open)
            {
                contest.Participants.Clear();
            }
            else
            {
                var participants = contest.Participants.ToList();

                foreach (var participantId in participantsIds)
                {
                    if (contest.Participants.All(p => p.Id != participantId))
                    {
                        var participant = this.ContestsData.Users.Find(participantId);
                        contest.Participants.Add(participant);
                    }
                }

                foreach (var participant in participants)
                {
                    if (!participantsIds.Contains(participant.Id))
                    {
                        contest.Participants.Remove(participant);
                    }
                }
            }
        }