public void CheckPermission(IPhotoContestData data, User user, Contest contest)
 {
     if (contest.Participants.Contains(user))
     {
         throw new BadRequestException("You cannot vote for contest that you currently participate in.");
     }
 }
예제 #2
0
        private static bool PictureCanBeVotedUnvoted(User user, Picture dbPicture, Contest dbContest)
        {
            // 1. User is author
            if (dbPicture.AuthorId == user.Id)
            {
                return false;
            }

            // 2. User is contest owner
            if (dbContest.OwnerId == user.Id)
            {
                return false;
            }

            //3. Contest is not Active
            if (dbContest.Status != PhotoContest.Models.Enumerations.ContestStatus.Active)
            {
                return false;
            }

            // 4. Contest is voted by Jury and user is not member of the Jury
            if (dbContest.VotingType == PhotoContest.Models.Enumerations.VotingType.Closed &&
                !dbContest.Jury.Members.Any(m => m.Id == user.Id))
            {
                return false;
            }

            return true;
        }
 public void CheckPermission(IPhotoContestData data, User user, Contest contest)
 {
     if (!contest.Committee.Contains(user))
     {
         throw new BadRequestException("User is not in the voting committee.");
     }
 }
 public void CheckPermission(IPhotoContestData data, User user, Contest contest)
 {
     if (!contest.IsOpenForSubmissions)
     {
         throw new BadRequestException("The contest registration is closed.");
     }
 }
예제 #5
0
        public static bool HasVotedForPicture(User user, Picture dbPicture, Contest dbContest)
        {
            if (dbPicture.Votes.Any(v => v.VoterId == user.Id && v.ContestId == dbContest.Id))
            {
                return true;
            }

            return false;
        }
예제 #6
0
        public static bool IsAuthor(User user, Picture dbPicture)
        {
            if (dbPicture.Author.Id ==user.Id)
            {
                return true;
            }

            return false;
        }
예제 #7
0
        protected override IAsyncResult BeginExecute(RequestContext requestContext, AsyncCallback callback, object state)
        {
            if (requestContext.HttpContext.User.Identity.IsAuthenticated)
            {
                var username = requestContext.HttpContext.User.Identity.Name;
                var user = this.Data.Users.All().FirstOrDefault(u => u.UserName == username);
                this.UserProfile = user;
            }

            return base.BeginExecute(requestContext, callback, state);
        }
예제 #8
0
        private void EditUserData(User user, UserDetails model)
        {

            user.UserName = model.UserName;
            user.PhoneNumber = model.PhoneNumber;
            user.Email = model.Email;

            this.Data.Users.Update(user);

            this.Data.SaveChanges();

            this.cache.RemoveContestsFromCache();
        }
        public void CheckDeadline(IPhotoContestData data, Contest contest, User user)
        {
            if (contest.SubmissionDeadline < DateTime.Now)
            {
                if (contest.IsOpenForSubmissions)
                {
                    contest.IsOpenForSubmissions = false;
                    data.Contests.Update(contest);
                    data.SaveChanges();
                }

                throw new BadRequestException("The contest is closed for submissions/registrations");
            }
        }
        public void CheckPermission(IPhotoContestData data, User user, Contest contest)
        {
            if (!contest.IsOpenForSubmissions)
            {
                throw new BadRequestException("The registration for this contest is closed.");
            }

            if (!contest.InvitedUsers.Contains(user))
            {
                throw new BadRequestException("The user is not selected to participate.");
            }

            var invitation = user.PendingInvitations.FirstOrDefault(i => i.ContestId == contest.Id);

            invitation.Status = InvitationStatus.Accepted;

            data.SaveChanges();
        }
예제 #11
0
        public static void AddSomeUsers()
        {
            var user1 = new User()
            {
                UserName = "******",
                Name = "Strahil1",
                Gender = UserGender.Male,
                BirthDate = new DateTime(2000,10,10)
            };

            var user2 = new User()
            {
                UserName = "******",
                Name = "Anatoli",
                Gender = UserGender.Male,
                BirthDate = new DateTime(2000, 10, 10)
            };

            var user3 = new User()
            {
                UserName = "******",
                Name = "Asya",
                Gender = UserGender.Female,
                BirthDate = new DateTime(2000, 10, 10)
            };

            var user4 = new User()
            {
                UserName = "******",
                Name = "Barish",
                Gender = UserGender.Male,
                BirthDate = new DateTime(2000, 10, 10)
            };

            dbContext.Users.Add(user1);
            dbContext.Users.Add(user2);
            dbContext.Users.Add(user3);
            dbContext.Users.Add(user4);
            dbContext.SaveChanges();
        }
 private bool HasParticipateInContest(int contestId, User user)
 {
     return user.ContestsParticipateIn.Any(x => x.Id == contestId);
 }
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new User { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User { UserName = model.Username, Email = model.Email};
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                var user = new User { UserName = model.Username, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (upload != null && upload.ContentLength > 0)
                {
                    var credentials = new StorageCredentials(AppKeys.Storage_Account_Name, AppKeys.PrimaryAccessKey);
                    var storageAccount = new CloudStorageAccount(credentials, true);
                    var blobClient = storageAccount.CreateCloudBlobClient();
                    imagesContainer = blobClient.GetContainerReference("images");
                    CloudBlockBlob image = await this.UploadBlobAsync(upload);
                    user.ProfileImageUrl = image.Uri.ToString();

                    //var imagePaths = Helpers.UploadImages.UploadImage(user.UserName,upload, true);
                    //var profilImageUrl = Dropbox.Download(imagePaths[0], "Profile");
                    //var profilThumbnailUrl = Dropbox.Download(imagePaths[1], "Thumbnails");
                    //user.ProfileImagePath = imagePaths[0];
                    //user.ThumbnailPath = imagePaths[1];
                    //user.ProfileImageUrl = profilImageUrl;
                    //user.ThumbnailUrl = profilThumbnailUrl;
                }
                result = await this.UserManager.UpdateAsync(user);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #16
0
        private void DeleteUserData(User user, UserDetails model)
        {
            var pictures = user.Pictures.ToList();
            for (int i = 0; i < pictures.Count(); i++)
            {
               DeletePicturetData(pictures[i]);
            }

            var contests = user.Contests.ToList();
            for (int i = 0; i < contests.Count(); i++)
            {
                this.DeleteContestData(contests[i]);
            }

            this.Data.Users.Delete(user);

            this.Data.SaveChanges();

            this.cache.RemoveContestsFromCache();
        }
예제 #17
0
 public static bool CanVoteForPicture(User user, Picture dbPicture, Contest dbContest)
 {
     return PictureCanBeVotedUnvoted(user, dbPicture, dbContest) && !HasVotedForPicture(user, dbPicture, dbContest);
 }
 protected BaseController(IPhotoContestData data, User user)
     : this(data)
 {
     this.UserProfile = user;
 }