예제 #1
0
        protected async Task HandleValidSubmit()
        {
            if (Id == 0)
            {
                var addedProfile = await ProfileService.AddProfile(OneProfile);

                if (addedProfile != null)
                {
                    StatusClass = "uk-text-success";
                    Message     = "New profile added successfully";
                    StateHasChanged();
                    await Task.Delay(2000);

                    NavigationManager.NavigateTo("/admin/profiles");
                }
                else
                {
                    StatusClass = "uk-text-danger";
                    Message     = "Something went wrong";
                }
            }
            else
            {
                await ProfileService.UpdateProfile(OneProfile);

                StatusClass = "uk-text-success";
                Message     = "Profile updated successfully";
                StateHasChanged();
                await Task.Delay(1000);

                NavigationManager.NavigateTo("/admin/profiles");
            }
        }
        public IActionResult Profile([FromBody] Profile newProfile)
        {
            Profile profile = profileService.AddProfile(newProfile);

            if (profile == null)
            {
                return(NotFound());
            }
            return(Ok(newProfile));
        }
예제 #3
0
        private void ParseProfileCmd(ProfileCmd baseCmd)
        {
            var parser       = new Parser(with => with.HelpWriter = null);
            var parserResult = parser
                               .ParseArguments <ProfileAdd, ProfileRm, ProfileLs, GetProfileActive, SetProfileActive, ProfileSetValue, ProfileGetValue>(baseCmd.SubArgs);

            parserResult
            .WithParsed <ProfileAdd>(args => profileService.AddProfile(args.Profile))
            .WithParsed <ProfileLs>(_ => profileService.ListProfiles())
            .WithParsed <ProfileRm>(args => profileService.RemoveProfile(args.Profile))
            .WithParsed <GetProfileActive>(args => Console.WriteLine(profileService.GetActiveProfile(true).Name))
            .WithParsed <SetProfileActive>(args => profileService.SetActiveProfile(args.Profile))
            .WithParsed <ProfileSetValue>(args => profileService.SetValue(args.Key, args.Value))
            .WithParsed <ProfileGetValue>(args => profileService.GetValue(args.Key))
            .WithNotParsed(_ => WriteHelpText(parserResult));
        }
예제 #4
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var profile = new Profile
                {
                    //creates a new profile from the view which passes to the service layer which then adds the rest of the info that we need and saves to DB as a new profile
                    FirstName     = model.FirstName,
                    LastName      = model.LastName,
                    DateOfBirth   = model.DateOfBirth,
                    RecoveryEmail = model.RecoveryEmail,
                    Email         = model.Email
                };
                var newProfile = _proServ.AddProfile(profile);

                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded && (newProfile != null))
                {
                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.Action(nameof(ConfirmEmail), "Account", new { userId = user.Id, code = code }, protocol: HttpContext.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);

                    _logger.LogInformation(3, "User created a new account with password.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #5
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // Add new profile
                    var _profileService = new ProfileService();
                    _profileService.AddProfile(new OnlineStore.Model.ViewModel.ProfileViewModel
                    {
                        UserId   = Guid.Parse(user.Id),
                        UserName = model.Email,
                        Emaill   = model.Email,
                        Password = model.Password,
                        Phone    = model.Phone,
                        Address  = model.Address
                    });

                    // 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>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #6
0
        public async Task <IActionResult> Register([FromBody] RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var profile = new Profile
                {
                    FirstName     = model.FirstName,
                    LastName      = model.LastName,
                    DateOfBirth   = model.DateOfBirth,
                    RecoveryEmail = model.RecoveryEmail,
                    Email         = model.Email
                };
                var profileResult = _profServ.AddProfile(profile);
                var user          = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded && (profileResult != null))
                {
                    // 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: HttpContext.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);

                    _logger.LogInformation(3, "User created a new account with password.");
                    var userViewModel = await GetUser(user.UserName);

                    return(Ok(userViewModel));
                }
                AddErrors(result);
            }

            // If we got this far, something failed
            return(BadRequest(this.ModelState));
        }
예제 #7
0
        public void TestService()
        {
            var             _options   = new DbContextOptionsBuilder <FunctionContext>().UseInMemoryDatabase("add_profile").Options;
            FunctionContext db_context = new FunctionContext(_options);

            ProfileService service = new ProfileService(db_context);

            var data = new ProfileModel {
                id       = 999,
                name     = "iFew",
                about_us = "Hello World!"
            };

            var response = service.AddProfile(data);

            var response_data = JsonConvert.DeserializeObject <ProfileModel>(response.Body);

            Assert.Equal(200, response.StatusCode);
            Assert.Equal("999", response_data.id.ToString());
            Assert.Equal("iFew", response_data.name);
            Assert.Equal("Hello World!", response_data.about_us);
        }
예제 #8
0
 public void Post([FromBody] ProfileDTO value)
 {
     _service.AddProfile(value, User.Identity.Name);
 }