Beispiel #1
0
        protected async Task HandleValidSubmit()
        {
            if (string.IsNullOrEmpty(User.Id)) //new
            {
                var addedUser = await UserDataService.AddUser(User);

                if (addedUser != null)
                {
                    StatusClass = "alert-success";
                    Message     = "New User added successfully.";
                    Saved       = true;
                }
                else
                {
                    StatusClass = "alert-danger";
                    Message     = "Something went wrong adding the new User. Please try again.";
                    Saved       = false;
                }
            }
            else
            {
                await UserDataService.UpdateUser(User);

                StatusClass = "alert-success";
                Message     = "User updated successfully.";
                Saved       = true;
            }
        }
 private void submitB_Click(object sender, EventArgs e)
 {
     if (usernameBox.Text == "")
     {
         MessageBox.Show("Put a valid Username..");
     }
     else if (passwordBox.Text == "")
     {
         MessageBox.Show("Put a valid Password..");
     }
     else
     {
         if (cpBox.Text != passwordBox.Text)
         {
             MessageBox.Show("Password and Confirm Password Doesnt Match!");
         }
         else
         {
             UserDataService userDataService = new UserDataService();
             int             result          = userDataService.AddUser(usernameBox.Text, passwordBox.Text);
             if (result > 0)
             {
                 MessageBox.Show("User Added Succesfully!");
                 this.Hide();
                 Login login = new Login();
                 login.Show();
             }
             else
             {
                 MessageBox.Show("Sorry There Was An Error!");
             }
         }
     }
 }
        protected async Task HandleValidSubmit()
        {
            Saved = false;
            var savedUser = new User();

            savedUser = await UserDataService.AddUser(User);

            if (savedUser != null && UserId == 0)
            {
                StatusClass = "alert-success";
                Message     = "New User Added Successfuly";
                Saved       = true;
            }
            else if (savedUser != null && UserId != 0)
            {
                StatusClass = "alert-success";
                Message     = "User Updated Successfuly";
                Saved       = true;
            }
            else
            {
                StatusClass = "alert-danger";
                Message     = "somthing went wrong adding the new user .please try again";
                Saved       = false;
            }
            ShowDialog = false;
            await CloseEventCallback.InvokeAsync(true);

            StateHasChanged();
            ToastService.ShowSuccess(Message, "Confirm");
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("id,login,password")] User user)
        {
            if (ModelState.IsValid)
            {
                await service.AddUser(user);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Beispiel #5
0
 public string AddUser(User user)
 {
     try
     {
         return(_userService.AddUser(user) ? "Amigo Add Successfully" : "Error Adding Amigo");
     }
     catch (Exception e)
     {
         return(e.Message);
     }
 }
Beispiel #6
0
        public async Task CreateUserTest()
        {
            var fakeRepository = Mock.Of <IAllRepo>();
            var movieService   = new UserDataService(fakeRepository);

            var user = new User()
            {
                login = "******", password = "******"
            };
            await movieService.AddUser(user);
        }
Beispiel #7
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = Input.Username, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    User newUser = new User()
                    {
                        FirstName = Input.FirstName,
                        LastName  = Input.LastName,
                        UserName  = Input.Username,
                        Email     = Input.Email,
                        Role      = Input.Role,
                    };
                    UserDataService userDataService = new UserDataService(AutoGraderDbContext);
                    userDataService.AddUser(newUser);

                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Beispiel #8
0
        private async Task CreateNewUserForApp()
        {
            var newUser = new UserForCreationModel()
            {
                Id        = UserInfoService.UserId,
                FirstName = UserInfoService.FirstName,
                LastName  = UserInfoService.LastName,
                UserName  = UserInfoService.FirstName + " " + UserInfoService.LastName
            };
            var createduser = await UserDataService.AddUser(newUser);

            if (createduser != null)
            {
                User = Mapper.Map <UserWithStatsModel>(createduser);
            }
        }
Beispiel #9
0
        public bool AddUser(Int64 Id, AddUser obj)
        {
            CommonHelper objCH     = new CommonHelper();
            long         RndmNumbr = objCH.GetRandomNumber(100000, 999999);

            obj.Password = objCH.EncryptData(RndmNumbr);
            obj.UserId   = objUDS.AddUser(Id, obj);
            if (obj.UserId > 0)
            {
                #region "Attachments"
                if (obj.UserImage != null && obj.UserImage.Content != "")
                {
                    try
                    {
                        byte[] bytes = null;
                        if (obj.UserImage.Content.IndexOf(',') >= 0)
                        {
                            var myString = obj.UserImage.Content.Split(new char[] { ',' });
                            bytes = Convert.FromBase64String(myString[1]);
                        }
                        else
                        {
                            bytes = Convert.FromBase64String(obj.UserImage.Content);
                        }

                        if (obj.UserImage.FileName.Length > 0 && bytes.Length > 0)
                        {
                            string filePath = System.Web.HttpContext.Current.Server.MapPath("/Attachments/UserImage/" + obj.UserId + "_" + obj.UserImage.FileName);
                            System.IO.File.WriteAllBytes(filePath, bytes);
                        }
                    }
                    catch (Exception ex) { }
                }
                #endregion

                return(true);
            }
            else
            {
                return(false);
            }
        }