예제 #1
0
 public void Update(User user)
 {
     var original = _dbContext.Users.FirstOrDefault(x => x.Id == user.Id);
     if(original==null)
         throw new Exception("Entity update not found");
     original.FirstName = user.FirstName;
     original.LastName = user.LastName;
     original.City = user.City;
     original.Country = user.Country;
     original.AvatarUrl = user.AvatarUrl;
     original.ReviewsCount = user.ReviewsCount;
     original.Rating = user.Rating;
     original.PositiveRatingPercent = user.PositiveRatingPercent;
     original.AvgResponseTimeMins = user.AvgResponseTimeMins;
     original.Balance = user.Balance;
     original.Hold = user.Hold;
     original.AvailableForWithdrawal = user.AvailableForWithdrawal;
     _dbContext.SaveChanges();
 }
예제 #2
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Account", "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 };
                user.RegistrationDate = DateTime.Now;
                var result = await _userManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    var avatarUrl = string.Format("http://graph.facebook.com/{0}/picture", info.Login.ProviderKey);
                    if (info.ExternalIdentity != null && info.ExternalIdentity.Claims != null)
                    {
                        var firstNameClaim =
                            info.ExternalIdentity.Claims.FirstOrDefault(x => x.Type == "urn:facebook:first_name");
                        if (firstNameClaim != null)
                            user.FirstName = firstNameClaim.Value;
                        var lastNameClaim =
                            info.ExternalIdentity.Claims.FirstOrDefault(x => x.Type == "urn:facebook:last_name");
                        if (lastNameClaim != null)
                            user.LastName = lastNameClaim.Value;
                    }
                    user.AvatarUrl = avatarUrl;
                    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);
        }
예제 #3
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User { UserName = model.Email, Email = model.Email };               
                user.ReferalCode = RandomCodeGenerator.Generate();
                user.RegistrationDate = DateTime.Now;
                
                if (!string.IsNullOrEmpty(model.RefCode))
                {
                    var refUser = _dbContext.Users.FirstOrDefault(x => x.ReferalCode == model.RefCode);
                    user.RefferedBy = refUser;
                }

                var result = await _userManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }