コード例 #1
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //if (UoW.UserRepository.Find(guy => guy.Username == user.Username))
                    //{
                    //    throw
                    //}

                    UoW.UserRepository.Add(user);
                    UoW.Save();
                }
                catch (Exception)
                {
                    ModelState.AddModelError(string.Empty, "Klarte ikke lagre brukeren.");
                }
            }
            else
            {
                return View();
            }

            return RedirectToAction("Index", "Posts");
        }
コード例 #2
0
 public ActionResult Create(User user)
 {
     if (ModelState.IsValid)
     {
         db.Users.Add(user);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(user);
 }
コード例 #3
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);
        }
コード例 #4
0
        public ActionResult Edit(User user)
        {
            if (user == null)
            {
                return RedirectToAction("Index");
            }

            if (ModelState.IsValid)
            {
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                return RedirectToAction("Index");
            }
            return View(user);
        }
コード例 #5
0
        public ActionResult Insert(User user)
        {
            ViewData["ShowForm"] = true;

            if (ModelState.IsValid)
            {
                AppServiceClient client = new AppServiceClient();
                ViewData["Result"] = client.Insert(
                    user.DegreeBefore,
                    user.Name,
                    user.Surname,
                    user.DegreeAfter,
                    user.Street,
                    user.StreetNumber,
                    user.Town,
                    user.Zipcode
                );
                ViewData["ShowForm"] = false;
            }
            return View(user);
        }
コード例 #6
0
 public BaseController(ISoftUniBlogData data, User user)
     : this(data)
 {
     this.UserProfile = user;
 }
コード例 #7
0
ファイル: AccountController.cs プロジェクト: mweimer/Blog
        private void CreateUser(string userName, string password)
        {
            var existingUser = from u in db.Users
                               where u.UserName == userName
                               select u;
            if (existingUser.Any())
                throw new MembershipCreateUserException(MembershipCreateStatus.DuplicateUserName);

            User user = new User();
            user.UserName = userName;
            user.Hash = SimpleHash.ComputeHash(password);

            db.Users.Add(user);
            db.SaveChanges();
        }
コード例 #8
0
        public async Task<ActionResult> Create(RegisterViewModel userViewModel, params string[] selectedRoles)
        {
            if (ModelState.IsValid)
            {
                var user = new User { UserName = userViewModel.Email, Email = userViewModel.Email };
                var adminresult = await UserManager.CreateAsync(user, userViewModel.Password);

                //Add User to the selected Roles 
                if (adminresult.Succeeded)
                {
                    if (selectedRoles != null)
                    {
                        var result = await UserManager.AddToRolesAsync(user.Id, selectedRoles);
                        if (!result.Succeeded)
                        {
                            ModelState.AddModelError("", result.Errors.First());
                            ViewBag.RoleId = new SelectList(await RoleManager.Roles.ToListAsync(), "Name", "Name");
                            return View();
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", adminresult.Errors.First());
                    ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name");
                    return View();

                }
                return RedirectToAction("Index");
            }
            ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name");
            return View();
        }
コード例 #9
0
ファイル: ManageController.cs プロジェクト: Mike920/BlogSite
 private async Task SignInAsync(User user, bool isPersistent)
 {
     AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie);
     AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, await user.GenerateUserIdentityAsync(UserManager));
 }
コード例 #10
0
ファイル: AccountController.cs プロジェクト: Mike920/BlogSite
        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);
        }
コード例 #11
0
ファイル: AccountController.cs プロジェクト: Mike920/BlogSite
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    var 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 this link: <a href=\"" + callbackUrl + "\">link</a>");
                    ViewBag.Link = callbackUrl;
                    return View("Registered");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #12
0
        private static void UserMethod(Blog.Models.User user)
        {
            while (true)
            {
                Console.WriteLine("USER");
                Console.WriteLine("You can: ");
                Console.WriteLine("Update yourself - 1");
                Console.WriteLine("Create blog - 2");
                Console.WriteLine("Update blog - 3");
                Console.WriteLine("See information about you - 4");
                Console.WriteLine("See your blogs - 5");
                Console.WriteLine("If you wanna exit press Esc");

                var action = Console.ReadKey();

                switch (action.Key)
                {
                case ConsoleKey.Escape:
                    return;

                case ConsoleKey.D1:
                    Console.Write("New Name: ");
                    var userName_1 = Console.ReadLine();
                    Console.Write("New Password: "******"Update ready!");
                    }
                    else
                    {
                        Console.WriteLine("Can't update");
                    }
                    break;

                case ConsoleKey.D2:
                    Console.Write("Blog's Name: ");
                    var blogName_2 = Console.ReadLine();
                    Console.Write("Blog's Text: ");
                    var blogText_2 = Console.ReadLine();
                    if (blogLogic.CreateBlog(user.UserId.ToString(), blogName_2, blogText_2))
                    {
                        Console.WriteLine("Create Blog!");
                    }
                    else
                    {
                        Console.WriteLine("Can't create blog");
                    }
                    break;

                case ConsoleKey.D3:
                    Console.Write("Blog's ID: ");
                    var blogId_3 = Console.ReadLine();
                    Console.Write("Blog's Rating: ");
                    var blogRating_3 = Console.ReadLine();
                    if (blogLogic.UpdateBlog(blogId_3, blogRating_3))
                    {
                        Console.WriteLine("Update ready!");
                    }
                    else
                    {
                        Console.WriteLine("Can't update");
                    }
                    break;

                case ConsoleKey.D4:
                    Console.WriteLine($"ID : {user.UserId}{Environment.NewLine}Name : {user.Name}{Environment.NewLine}Password : {user.Password}{Environment.NewLine}Role : {user.Role}{Environment.NewLine}");
                    break;

                case ConsoleKey.D5:
                    var result_5 = blogLogic.GetBlogsByUser(user.UserId.ToString());
                    if (result_5 != null)
                    {
                        foreach (var item in result_5)
                        {
                            Console.WriteLine($"ID : {item.BlogId}{Environment.NewLine}Name : {item.Name}{Environment.NewLine}Rating : {item.Rating}{Environment.NewLine}Text : {Environment.NewLine}{item.Text}{Environment.NewLine}");
                        }
                    }
                    else
                    {
                        Console.WriteLine("You haven't blogs");
                    }
                    break;

                default:
                    break;
                }
            }
        }