public static Contest IsContestValid(IContestsData context, User creator, int contestId) { var contest = context.Contests.All() .FirstOrDefault(c => c.IsActive && c.Id == contestId); if (contest != null) { if (contest.ParticipationType == ParticipationType.Open && !HttpContext.Current.User.Identity.IsAuthenticated) { return null; } if (contest.ParticipationType == ParticipationType.Closed && !(contest.Participants.Any(p => p.Id == creator.Id))) { return null; } if (contest.DeadlineType == DeadlineType.ByParticipants && (contest.Photos.DistinctBy(p => p.OwnerId).Count() > contest.ParticipantsNumberDeadline)) { return null; } if (contest.DeadlineType == DeadlineType.ByTime && DateTime.Now >= contest.DeadLine) { return null; } } return contest; }
public static UserEditBindingModel CreateFromUser(User user) { var newUser = new UserEditBindingModel() { UserName = user.UserName, FullName = user.FullName, Email = user.Email, PhoneNumber = user.PhoneNumber, Upload = null, RegisteredOn = user.RegisteredOn, ProfilePhotoPath = user.ProfilePhotoPath, ThumbnailPath = user.ThumbnailPath, ProfilePhotoUrl = user.ProfilePhotoUrl, ThumbnailUrl = user.ThumbnailUrl }; return newUser; }