Exemplo n.º 1
0
        public void AddUserDetails()
        {
            user.Name      = txtName.Text;
            user.Phone     = txtPhone.Text;
            user.Address   = txtAddress.Text;
            user.Education = txtEducation.Text;

            UserServices userServices = new UserServices();

            if (txtName.Text == "" || txtPhone.Text == "" || txtAddress.Text == "" || txtEducation.Text == "")
            {
                MessageBox.Show("Please fill all the items");
            }
            else
            {
                if (userServices.Add(human) == 1)
                {
                    MessageBox.Show("Record Added Successfully!");
                }
                else
                {
                    MessageBox.Show("Could not store data!!");
                }
            }
        }
Exemplo n.º 2
0
        public CommonRtnEntity Add([FromBody] UserInfo info)
        {
            IUserServices services = new UserServices();

            int result = 0;

            //编辑
            if (info.ID > 0)
            {
                UserInfo oldUserInfo = services.QueryByID(info.ID);
                if (oldUserInfo != null)
                {
                    info.Pwd = oldUserInfo.Pwd;
                }
                info.UpdateTime = DateTime.Now;
                services.Update(info);
                result = info.ID;
            }
            else
            {
                result = services.Add(info);
            }

            CommonRtnEntity rtnInfo = new CommonRtnEntity()
            {
                Success = result > 0,
                Data    = result,
                Message = result > 0 ? "添加成功!" : "添加失败!"
            };

            return(rtnInfo);
        }
Exemplo n.º 3
0
        private void addUser(string Name, string LastName, string User, string Password, string Password_Confirm)
        {
            if (Password == Password_Confirm)
            {
                bool result = userServices.GetUser(User, false);

                if (!result)
                {
                    user.Nombre     = Name;
                    user.Apellido   = LastName;
                    user.Usuario    = User;
                    user.Contraseña = Password;
                    userServices.Add(user);
                    MessageBox.Show("Usuario agregado satisfactoriamente");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Nombre de usuario no disponible");
                }
            }
            else
            {
                MessageBox.Show("Las contraseñas no coinciden");
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateUser(JobsViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = viewModel.Email, Email = viewModel.Email
                };
                var result = await userManager.CreateAsync(user, viewModel.Passsword);

                if (result.Succeeded)
                {
                    var identityRole = await roleManager.FindByIdAsync(viewModel.JobId);

                    await userManager.AddToRoleAsync(user, identityRole.Name.ToString());
                }
                var newidentityRole = await roleManager.FindByIdAsync(viewModel.JobId);

                var createdUser = await userManager.FindByEmailAsync(viewModel.Email);

                userServices.Add(createdUser.Id, viewModel.Name, viewModel.Surname, viewModel.PhoneNr);
                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("CreateUser"));
        }
        public ActionResult Create(User u, HttpPostedFileBase file)
        {
            us.Add(u);
            us.Commit();

            return(RedirectToAction("Create"));
        }
Exemplo n.º 6
0
        protected void button_register(object sender, EventArgs e)
        {
            try
            {
                string message          = "";
                string namefield        = name.Value.Trim();
                string emailField       = email.Value.Trim();
                string companyField     = company.Value;
                string phoneField       = phone.Value;
                string passwordField    = password.Value;
                string confirmPassField = confirmpassword.Value;

                if (!passwordField.Equals(confirmPassField, StringComparison.OrdinalIgnoreCase))
                {
                    message = "Invalid Password Combination. Please check your password";
                    errorMessage.InnerText = message;
                    labelDiv.Attributes.Add("display", "block");
                    return;
                }

                UserServices.Add(namefield, emailField, phoneField, passwordField, confirmPassField, companyField);
            }
            catch
            {
                Response.Redirect(FormsAuthentication.LoginUrl);
            }
        }
Exemplo n.º 7
0
        public IActionResult Add(string username, string password, string email, string type)
        {
            User model = new User()
            {
                Username    = username,
                Password    = password,
                Email       = email,
                Type        = type,
                Hash        = "",
                CreatedDate = DateTime.Now,
                CreatedBy   = "web",
                UpdatedDate = DateTime.Now,
                UpdatedBy   = "web"
            };

            UserServices uss       = new UserServices(_config);
            var          isDupUser = uss.GetByUsername(username);

            if (isDupUser != null)
            {
                return(Ok(new ResponseResult(200, StatusMessage.Error.ToString(), "Username is duplicate")));
            }

            uss.Add(model);
            return(Ok(new ResponseResult(200, StatusMessage.Completed.ToString(), "", model)));
        }
Exemplo n.º 8
0
        public void ShouldReturnSuccessForAdd()
        {
            UserModel um = new UserModel()
            {
                UserEmail      = "*****@*****.**",
                UserName       = "******",
                UserPassword   = "******",
                UserRestaurant = 1
            };
            bool   operationSucceeded      = false;
            string dataAccessStatusJsonStr = string.Empty;
            string formatedJsonString      = string.Empty;

            try
            {
                _userServices.Add(um);
                operationSucceeded = true;
            }
            catch (DataAccessException dataAccessException)
            {
                operationSucceeded      = dataAccessException.DataAccessStatusInfo.OperationSucceded;
                dataAccessStatusJsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(dataAccessException.DataAccessStatusInfo);
                formatedJsonString      = JToken.Parse(dataAccessStatusJsonStr).ToString();
            }
            try
            {
                Assert.True(operationSucceeded);
                _testOutputHelper.WriteLine("The user was successfully added");
            }
            finally
            {
                _testOutputHelper.WriteLine(formatedJsonString);
            }
        }
Exemplo n.º 9
0
        public ActionResult Add(AddUserViewModel userViewModel)
        {
            if (userManager.HasUsername(userViewModel.Username))
            {
                ModelState.AddModelError("Username", "用户名已存在");
            }
            if (userManager.HasEmail(userViewModel.Email))
            {
                ModelState.AddModelError("Email", "Email已存在");
            }
            if (ModelState.IsValid)
            {
                User _user = new User();
                _user.RoleID   = userViewModel.RoleID;
                _user.Username = userViewModel.Username;
                _user.Name     = userViewModel.Name;
                _user.Sex      = userViewModel.Sex;
                _user.Password = Security.SHA256(userViewModel.Password);
                _user.Email    = userViewModel.Email;
                _user.RegTime  = System.DateTime.Now;
                var _response = userManager.Add(_user);
                if (_response.Code == 1)
                {
                    return(View("Prompt", new Prompt()
                    {
                        Title = "添加用户成功",
                        Message = "您已成功添加了用户【" + _response.Data.Username + "(" + _response.Data.Name + ")】",
                        Buttons = new List <string> {
                            "<a href=\"" + Url.Action("Index", "User") + "\" class=\"btn btn-default\">用户管理</a>",
                            "<a href=\"" + Url.Action("Details", "User", new { id = _response.Data.UserID }) + "\" class=\"btn btn-default\">查看用户</a>",
                            "<a href=\"" + Url.Action("Add", "User") + "\" class=\"btn btn-default\">继续添加</a>"
                        }
                    }));
                }
                else
                {
                    ModelState.AddModelError("", _response.Message);
                }
            }
            //角色列表
            var _roles = new RoleServices().FindList();
            List <SelectListItem> _listItems = new List <SelectListItem>(_roles.Count());

            foreach (var _role in _roles)
            {
                _listItems.Add(new SelectListItem()
                {
                    Text = _role.Name, Value = _role.RoleID.ToString()
                });
            }
            ViewBag.Roles = _listItems;
            //角色列表结束

            return(View(userViewModel));
        }
Exemplo n.º 10
0
 private void Save()
 {
     if (userServices.Add(txtNombre.Text, txtApellido.Text, txtMail.Text, txtUsuario.Text, txtContra.Text, pictureBox1.ImageLocation))
     {
         MessageBox.Show("Usuario agregado correctamente");
     }
     else
     {
         MessageBox.Show("El usuario no pudo ser agregado");
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// 新增用户操作
        /// </summary>
        /// <param name="u"></param>
        /// <returns></returns>
        public ActionResult memberAdd(User u)
        {
            bool i = us.Add(u);

            if (i)
            {
                return(Content(Ts("新增成功!", "../Frontdesk/member_list")));
            }
            else
            {
                return(Content(Ts("新增失败!", "../Frontdesk/member_Add")));
            }
        }
Exemplo n.º 12
0
        public void Add()
        {
            string x = UserServices.Add(firstName, lastName, birthTime, email, phone);

            if (x == null)
            {
                TryClose();
            }
            else
            {
                Error = x;
            }
        }
Exemplo n.º 13
0
 public ActionResult Create(RoleUserViewModel ObjRoleUserViewModel)
 {
     if (ModelState.IsValid)
     {
         //for role
         List <Role> lstRol = new List <Role>();
         foreach (int x in ObjRoleUserViewModel.SpecifiedSelected)
         {
             lstRol.Add(new Role(x));
         }
         _UserServices.Add(ObjRoleUserViewModel._User, lstRol);
         return(RedirectToAction("Index"));
     }
     return(View("Create", ObjRoleUserViewModel));
 }
Exemplo n.º 14
0
        private void addUserBtn_Click(object sender, EventArgs e)
        {
            string userEmail         = emailTB.Text;
            string userName          = nameTB.Text;
            string userPassword      = passwordTB.Text;
            string _connectionString = "Data Source=" +
                                       Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\OO_PocketGourmet_REAL-UnitTest\MVPDB.sqlite;";
            UserServices userServices = new UserServices(new UserRepository(_connectionString), new ModelDataAnnotationCheck());
            UserModel    user         = new UserModel()
            {
                UserEmail      = userEmail,
                UserName       = userName,
                UserPassword   = userPassword,
                UserRestaurant = restaurantID
            };

            userServices.Add(user);

            MessageBox.Show("User Added");
        }
Exemplo n.º 15
0
        public void Post([FromBody] UserProfile user)
        {
            try
            {
                UserProfile _user = AuthManager.CurrentUser;
                if (_user != null)
                {
                    throw new RequestForbidden(new ErrorResponse(ErrorResponseCode.UserAccessDenied, Messages.RequestForbidden));
                }

                if (user == null)
                {
                    throw new RequestForbidden(new ErrorResponse(ErrorResponseCode.InvalidRequestError, Messages.InvalidRequest));
                }

                UserServices.Add(user.Name, user.Email, user.Phone, user.Password, user.ConfirmPassword, user.Company);
            }
            catch
            {
            }
        }
Exemplo n.º 16
0
        public async Task <JsonResult> CreateNewUser(string param)
        {
            string[] words = param.Split(' ');
            User     user  = new User
            {
                login    = words[0],
                password = words[1]
            };
            UserServices userServices = new UserServices();

            if (userServices.CheckUser(user))
            {
                return(Json("user exist", JsonRequestBehavior.AllowGet));
            }
            else
            {
                login = user.login;
                await userServices.Add(user);

                return(Json("thank for registration", JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 17
0
        public ActionResult Add(User user)
        {
            user.IsActive = true;
            // MD5加密
            user.Password = SecurityHelper.str2md5(user.Password);
            // 将时间转换为时间戳
            user.CreateTime = TimeHelper.ConvertDateTimeInt(DateTime.Now);
            // 受影响的行数(为1,则表示成功)
            int issuccess = userInfo.Add(user);

            //if (issuccess > 0)
            //{
            //    return Content("ok");
            //}
            //else
            //{
            //    return Content("no");
            //}
            if (issuccess == 1)
            {
                var ret = new
                {
                    message = true
                };
                // 返回json
                return(Json(ret, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var ret = new
                {
                    message = false
                };
                return(Json(ret, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 18
0
 private void btnNC_Click(object sender, EventArgs e)
 {
     if (txtPassCon.Text != "" | txtPass.Text != "")
     {
         if (txtPassCon.Text == txtPass.Text)
         {
             if (txtName.Text != "" | txtLastName.Text != "" | dtpBirth.Text != "" | txtUser.Text != "" | cbType.Text != "")
             {
                 user.NAME     = txtName.Text;
                 user.LASTNAME = txtLastName.Text;
                 if (cbType.Text == "Administrador")
                 {
                     user.TYPE = 0;
                 }
                 else
                 {
                     user.TYPE = 1;
                 }
                 user.BIRTH    = dtpBirth.Value;
                 user.USER     = txtUser.Text;
                 user.PASSWORD = txtPass.Text;
                 user.CAREER   = txtCareer.Text;
                 user.MAIL     = txtMail.Text;
                 UserServices userServices = new UserServices();
                 if (Edit)
                 {
                     user.ID = userEdit.ID;
                     if (userServices.Edit(user))
                     {
                         MessageBox.Show("Usuario editado correctamente");
                         this.Hide();
                     }
                     else
                     {
                         MessageBox.Show("No se pudo completar la accion");
                     }
                 }
                 else
                 {
                     if (userServices.Add(user))
                     {
                         MessageBox.Show("Usuario agregado correctamente");
                         this.Hide();
                     }
                     else
                     {
                         MessageBox.Show("No se pudo completar la accion");
                     }
                 }
             }
             else
             {
                 MessageBox.Show("Debe llenar todos los campos");
             }
         }
         else
         {
             MessageBox.Show("Las contraseñas no coinciden");
         }
     }
     else
     {
         MessageBox.Show("Debe llenar todos los campos");
     }
 }
Exemplo n.º 19
0
        public IActionResult Post([FromBody] UserModel request)
        {
            UserSessionManager usrSession   = new UserSessionManager();
            var             user            = User as ClaimsPrincipal;
            string          userId          = user.Claims.Where(c => c.Type == "USERID").Select(c => c.Value).SingleOrDefault();
            UserModelOutput userModelOutput = new UserModelOutput();

            try
            {
                _logger.Information("Saving User");
                DisplayUser displayUser = new DisplayUser();
                var         query       = new List <UserModel>((List <UserModel>)displayUser.DisplayAll()).AsQueryable();
                var         CheckEmail  = query.Where(p => p.user_email.StartsWith(request.user_email ?? String.Empty, StringComparison.InvariantCultureIgnoreCase));

                if (CheckEmail.Count() > 0)
                {
                    ModelState.AddModelError("Email", "Email already exists");
                }

                if (ModelState.IsValid)
                {
                    UserServices userServices = new UserServices
                    {
                        objUser = usrSession.UserLog(userId)._userInfo
                    };
                    var res = userServices.Add(request);
                    userModelOutput.IsSuccess = true;
                    userModelOutput.Message   = "Success Saving";
                    userModelOutput.Code      = 200;
                }
                else
                {
                    _logger.Error("Error Post Account");


                    string errordetails = "";
                    var    errors       = new List <string>();
                    foreach (var state in ModelState)
                    {
                        foreach (var error in state.Value.Errors)
                        {
                            string p = error.ErrorMessage;
                            errordetails = errordetails + error.ErrorMessage;
                        }
                    }
                    Dictionary <string, object> dict = new Dictionary <string, object>();
                    dict.Add("error", errordetails);

                    userModelOutput.IsSuccess   = false;
                    userModelOutput.Message     = "error saving validating";
                    userModelOutput.Code        = 422;
                    userModelOutput.CustomField = dict;
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message.ToString());
                userModelOutput.IsSuccess = false;
                userModelOutput.Message   = "Failed Saving" + ex.Message;
                userModelOutput.Code      = 422;
            }

            return(Ok(userModelOutput));
        }
Exemplo n.º 20
0
        public ActionResult AddNewResident(UserInfoViewModel user)
        {
            MessageViewModels response = new MessageViewModels();

            if (null != user.HouseId)
            {
                try
                {
                    House house = _houseServices.FindById(user.HouseId);
                    if (null != house)
                    {
                        User u = new User();
                        if (house.Status == SLIM_CONFIG.HOUSE_STATUS_ENABLE && house.OwnerID == null && user.IsHouseOwner == SLIM_CONFIG.USER_ROLE_RESIDENT)
                        {
                            response.StatusCode = 2;
                            response.Msg        = "Nhà này vẫn chưa có chủ hộ !";
                            return(Json(response));
                        }

                        u.Fullname     = user.Name;
                        u.HouseId      = house.Id;
                        u.CreateDate   = DateTime.Now;
                        u.LastModified = DateTime.Now;
                        u.IDNumber     = user.Idenity;
                        u.Status       = SLIM_CONFIG.USER_STATUS_ENABLE;
                        u.Gender       = user.Gender;
                        u.DateOfBirth  = DateTime.ParseExact(user.Dob, AmsConstants.DateFormat, CultureInfo.CurrentCulture);
                        if (user.IdCreateDate != null)
                        {
                            u.IDCreatedDate = DateTime.ParseExact(user.IdCreateDate, AmsConstants.DateFormat, CultureInfo.CurrentCulture);
                        }
                        u.Username    = user.UserAccountName;
                        u.Creator     = Int32.Parse(User.Identity.GetUserId());
                        u.RoleId      = user.IsHouseOwner;
                        u.FamilyLevel = user.RelationLevel;
                        if (user.IsHouseOwner == SLIM_CONFIG.USER_ROLE_HOUSEHOLDER)
                        {
                            u.FamilyLevel = 0; // At the center row in house
                        }
                        u.Password       = CommonUtil.GetUniqueKey(8);
                        u.SendPasswordTo = user.CellNumb;
                        _userServices.Add(u);
                        if (user.IsHouseOwner == SLIM_CONFIG.USER_ROLE_HOUSEHOLDER)
                        {
                            house.OwnerID = u.Id;
                            _houseServices.Update(house);

                            foreach (var userInHouse in house.Users.Where(usr => usr.Id != u.Id && u.RoleId == SLIM_CONFIG.USER_ROLE_HOUSEHOLDER)
                                     )
                            {
                                User usr = _userServices.FindById(userInHouse.Id);
                                usr.RoleId       = SLIM_CONFIG.USER_ROLE_RESIDENT;
                                usr.LastModified = DateTime.Now;
                                _userServices.Update(usr);
                            }
                        }

                        StringBuilder message = new StringBuilder();
                        message.Append("Chung cu AMS. Tai khoan duoc tao thanh cong! Ten đang nhap: ")
                        .Append(u.Username)
                        .Append(". Mat khau: ")
                        .Append(u.Password);
                        CommonUtil.SentSms(u.SendPasswordTo, message.ToString());

                        //                    var accountSid = "AC10ae7ed64035004a9f1ed772747b94dc"; // Your Account SID from www.twilio.com/console
                        //                    var authToken = "c867c6dadb271752b1fa0bb988f1c284";  // Your Auth Token from www.twilio.com/console
                        //
                        //                    var twilio = new TwilioRestClient(accountSid, authToken);
                        //                    var message = twilio.SendMessage(
                        //                        "+12057198424", // From (Replace with your Twilio number)
                        //                        "+84934876200", // To (Replace with your phone number)
                        //                        "One time password: chào bạn"
                        //                        );
                        //
                        //                    Console.WriteLine(message.Sid);
                        //                    Console.Write("Press any key to continue.");
                        //                    Console.ReadKey();
                    }
                    else
                    {
                        response.StatusCode = -1;
                    }
                }
                catch (Exception)
                {
                    response.StatusCode = -1;
                    return(Json(response));
                }
            }
            else
            {
                response.StatusCode = -1;
            }

            return(Json(response));
        }
Exemplo n.º 21
0
        public async Task <IActionResult> Post(UserAddDto users)
        {
            await _userServices.Add(_mapper.Map <Users>(users));

            return(NoContent());
        }