public ActionResult Users_Destroy([DataSourceRequest]DataSourceRequest request, ApplicationUser user)
        {
            var userToDelete = this.users.GetById(user.Id);
            this.users.Delete(userToDelete);

            return this.Json(new[] { user }.ToDataSourceResult(request, this.ModelState));
        }
        public ActionResult Users_Create([DataSourceRequest]DataSourceRequest request, UserGridInputModel user)
        {
            var newId = string.Empty;
            if (this.ModelState.IsValid)
            {
                var entity = new ApplicationUser
                {
                    UserName = user.UserName,
                    Email = user.Email,
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    Age = user.Age,
                    ImageId = 2
                };

                this.users.Create(entity, user.Password);
                newId = entity.Id;
            }

            var userToDisplay = this.users
                .GetAll()
                .To<UserGridViewModel>()
                .FirstOrDefault(x => x.Id == newId);

            return this.Json(new[] { userToDisplay }.ToDataSourceResult(request, this.ModelState));
        }
Example #3
0
 public void Update(ApplicationUser user)
 {
     var store = new UserStore<ApplicationUser>(this.Context);
     var userManager = new UserManager<ApplicationUser>(store);
     var context = store.Context;
     userManager.Update(user);
     context.SaveChanges();
 }
Example #4
0
 public void Delete(ApplicationUser user)
 {
     var userStore = new UserStore<ApplicationUser>(this.Context);
     var userManager = new UserManager<ApplicationUser>(userStore);
     userManager.Delete(user);
     var context = userStore.Context;
     context.SaveChanges();
 }
Example #5
0
 public void Create(ApplicationUser user, string password)
 {
     var userStore = new UserStore<ApplicationUser>(this.Context);
     var userManager = new UserManager<ApplicationUser>(userStore);
     userManager.Create(user, password);
     var context = userStore.Context;
     context.SaveChanges();
 }
Example #6
0
 public void Join(string tripId, ApplicationUser user)
 {
     var tripToJoin = this.GetById(tripId);
     tripToJoin.Passengers.Add(user);
     tripToJoin.AvailableSeats -= 1;
     this.trips.Save();
     user.Trips.Add(tripToJoin);
     this.users.Update(user);
 }
Example #7
0
        public async Task<ActionResult> ExternalLoginConfirmation(
            ExternalLoginConfirmationViewModel model,
            string returnUrl)
        {
            if (this.User.Identity.IsAuthenticated)
            {
                return this.RedirectToAction("Index", "Manage");
            }

            if (this.ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await this.AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return this.View("ExternalLoginFailure");
                }

                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await this.UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await this.UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await this.SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return this.RedirectToLocal(returnUrl);
                    }
                }

                this.AddErrors(result);
            }

            this.ViewBag.ReturnUrl = returnUrl;
            return this.View(model);
        }
Example #8
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var vehicle = new Vehicle();
                if (model.IsDriver)
                {
                    vehicle = new Vehicle()
                    {
                        Model = model.CarModel,
                        Brand = model.CarBrand,
                        RegistrationNumber = model.CarRegistrationNumber,
                        Year = model.CarYear,
                        Color = model.CarColor
                    };
                }

                var user = new ApplicationUser
                {
                    UserName = model.Email,
                    Email = model.Email,
                    FirstName = model.FirstName,
                    LastName = model.Lastname,
                    Age = model.Age,
                    ImageId = 2
                };
                var result = await this.UserManager.CreateAsync(user, model.Password);
                if (model.IsDriver)
                {
                    vehicle.DriverId = user.Id;
                    this.vehicles.Create(vehicle);
                }

                if (result.Succeeded)
                {
                    await this.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>");
                    if (model.IsDriver)
                    {
                        this.UserManager.AddToRole(user.Id, GlobalConstants.DriverRoleName);
                    }
                    else
                    {
                        this.UserManager.AddToRole(user.Id, GlobalConstants.PassengerRoleName);
                    }

                    return this.RedirectToAction("Index", "Home");
                }

                this.AddErrors(result);
            }

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