예제 #1
0
        public async Task <IActionResult> NextAccountID()
        {
            var newID = await Task.Run <string>(() => {
                return(IDGenerator.GetMemberIDGenerator(_applicationDbContext)
                       .GetNext());
            });

            return(new JsonResult(new { NextAccountID = newID ?? "" }));
        }
예제 #2
0
        public async Task <ActionResult> NextAccountID()
        {
            var newID = await Task.Run <string>(() => {
                var cacheID = Session["NextMemberID"];
                if (cacheID == null)
                {
                    cacheID = IDGenerator.GetMemberIDGenerator(this.AppDbContext).GetNext();
                    Session.Add("NextMemberID", cacheID);
                }
                return(cacheID.ToString());
            });

            return(JsonMessage.JsonResult(new { NextAccountID = newID ?? "" }));
        }
예제 #3
0
        //[AllowAnonymous]
        //[ValidateAntiForgeryToken]
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                Member menberReference = null;
                string refID           = model.ReferenceID;
                if (String.IsNullOrWhiteSpace(refID))
                {
                    var role = this.RoleManager.FindByName("Administrator").Users.FirstOrDefault();

                    var adminUser = (await this.UserManager.FindByIdAsync(role.UserId));
                    if (adminUser != null)
                    {
                        refID = adminUser.UserName;
                    }
                }

                if (String.IsNullOrWhiteSpace(refID) == false)
                {
                    menberReference = await(from m in this.AppDbContext.Members
                                            where m.MemberID.Equals(refID)
                                            select m
                                            ).FirstOrDefaultAsync();
                }

                if (menberReference == null)
                {
                    return(JsonMessage.BadRequestJsonResult("ReferenceID is not exist."));
                }

                var member = new Member
                {
                    MemberID  = IDGenerator.GetMemberIDGenerator(this.AppDbContext).GetNext(),
                    Reference = menberReference,
                    Name      = model.Name,
                    IDCard    = model.CardID,
                    Address   = model.Address,
                    Level     = model.Level
                };

                var user = new ApplicationUser
                {
                    Id          = member.MemberID,
                    UserName    = member.MemberID,
                    MemberInfo  = member,
                    PhoneNumber = model.Phone
                };

                this.AppDbContext.Members.Add(member);

                var result = await this.UserManager.CreateAsync(user, ApplicationUser.IINT_PASSWORD);

                if (result.Succeeded)
                {
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Context.Request.Scheme);
                    //await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                    //    "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
                    //await _signInManager.SignInAsync(user, isPersistent: false);
                    //return RedirectToAction(nameof(HomeController.Index), "Home");

                    Session.Remove("NextMemberID");
                    return(JsonMessage.JsonResult(member.MemberID));
                }
                AddErrors(result);
            }

            return(JsonMessage.BadRequestJsonResult(ModelState.Values.SelectMany(x => x.Errors)));
        }