Ejemplo n.º 1
0
 public string GetTheBest()
 {
     using (var context = new SkillInfoContext())
     {
         var userId = context.UserSkills.GroupBy(u => u.UserId)
             .Select(g => new {UserId = g.Key, Marks = g.Sum(m => m.Mark)})
             .OrderByDescending(d => d.Marks)
             .First()
             .UserId;
         var name = context.UserProfiles.Where(u => u.UserId == userId).Select(u => u.UserName).First();
         return name;
     }
 }
Ejemplo n.º 2
0
 public Dictionary<string, string> GetBirthdayUsers()
 {
     using (var context = new SkillInfoContext())
     {
         var users = context.UserProfiles.Where(
             user =>
                 user.Birthday.HasValue &&
                 user.Birthday.Value.Year == DateTime.Now.Year &&
                 user.Birthday.Value.Month == DateTime.Now.Month &&
                 user.Birthday.Value.Day == DateTime.Now.Day)
             .Select(user => new {user.UserName, user.Email});
         return users.ToDictionary(user => user.UserName, user => user.Email);
     }
 }
Ejemplo n.º 3
0
 public SearchRepository(SkillInfoContext context)
 {
     _context = context;
 }
Ejemplo n.º 4
0
 public ActionResult ManageBirthday(BirthdayModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             using (SkillInfoContext db = new SkillInfoContext())
             {
                 // Set Birthday date to the current user
                 var user = db.UserProfiles.FirstOrDefault(u => u.UserName == User.Identity.Name);
                 if (user != null)
                 {
                     user.Birthday = model.Date;
                 }
                 db.SaveChanges();
             }
             return RedirectToAction("Index", "Home");
         }
         catch
         {}
     }
     return View("Manage");
 }
Ejemplo n.º 5
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (SkillInfoContext db = new SkillInfoContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile { UserName = model.UserName });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return RedirectToLocal(returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }