Пример #1
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            m_user.userID = txtCode.Text;
            m_user.name   = txtName.Text;
            m_user.age    = Convert.ToInt32(txtAge.Text);
            m_user.sex    = cboSex.Text;
            string[] arr = cboPlace.Text.Split(' ');
            m_user.cityNo  = arr[0];
            m_user.summary = txtSummary.Text;

            try
            {
                if (m_bAdd)
                {
                    m_userBLL.AddUser(m_user);
                }
                else
                {
                    m_userBLL.UpdateUser(m_user);
                }
            }
            catch (UserDBException ex)
            {
                MessageBox.Show(ex.Message);
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
Пример #2
0
        public IActionResult Post([FromBody] JObject value)
        {
            if (value == null)
            {
                return(BadRequest());
            }

            try
            {
                var userVm = value.ToObject <UserViewModel>();
                var user   = _mapper.Map <UserEntity>(userVm);

                var id = _userBll.AddUser(user);

                if (id == -1)
                {
                    return(BadRequest());
                }

                return(Created("", new { id }));
            }
            catch
            {
                return(BadRequest());
            }
        }
Пример #3
0
        public JsonResult AddUser([FromBody] AddUserRequest request)
        {
            var result = userBll.AddUser(request.UserName);

            if (result)
            {
                return(new JsonResult(new ApiResponse(1, "", true)));
            }
            else
            {
                return(new JsonResult(new ApiResponse(2, "", false)));
            }
        }
Пример #4
0
        public HttpResponseMessage AddUser(UserDTO userDTO)
        {
            try
            {
                if (userDTO == null)
                {
                    throw new ArgumentNullException("userDTO");
                }

                UserDTO _Output = _IUserBLL.AddUser(userDTO);
                return(Request.CreateResponse(HttpStatusCode.OK, _Output));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Пример #5
0
        public void CreateNewUser()
        {
            Console.WriteLine("Insert username:"******"Insert Date of Birth");
            }while (!DateTime.TryParseExact(Console.ReadLine(), "dd/MM/yyyy", CultureInfo.InvariantCulture,
                                            DateTimeStyles.None,
                                            out dob));

            int age = InsertValidation.InsertIntRange(1, 100);

            _userLogic.AddUser(name, dob, age);
        }
Пример #6
0
        public ActionResult SignUp(SignupModel signupModel, HttpPostedFileBase Avatar)
        {
            if (ModelState.IsValid)
            {
                string image     = "";
                byte[] imageData = null;
                if (Avatar != null)
                {
                    using (var binaryReader = new BinaryReader(Avatar.InputStream))
                    {
                        imageData = binaryReader.ReadBytes(Avatar.ContentLength);
                    }
                    image = Convert.ToBase64String(imageData);
                }
                else
                {
                    image = SignupModel.defaultavatar;
                }
                MailAddress from = new MailAddress("*****@*****.**", "Registration");
                MailAddress to   = new MailAddress(signupModel.Email);
                MailMessage msg  = new MailMessage(from, to);
                msg.Subject    = "Подтверждение регистрации";
                msg.Body       = string.Format("Для завершения регистрации перейдите по ссылке: " + "<a href=\"{0}\" title=\"Подтвердить регистрацию\">{0}</a>", Url.Action("ConfirmEmail", "User", new { userName = signupModel.Login, email = signupModel.Email }, Request.Url.Scheme));
                msg.IsBodyHtml = true;

                SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
                smtp.UseDefaultCredentials = false;
                smtp.Credentials           = new NetworkCredential("*****@*****.**", "dD89271518969");
                smtp.EnableSsl             = true;
                smtp.Send(msg);

                if (_userLogic.AddUser(signupModel.Login, signupModel.Password, signupModel.Email, image))
                {
                    return(RedirectToAction("Confirm", "User", new { email = signupModel.Email }));
                }
                else
                {
                    return(View(signupModel));
                }
            }
            return(View(signupModel));
        }
Пример #7
0
        public IActionResult Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            else
            {
                if (_userBLL.GetUserByEmail(model.Email) != null)
                {
                    ModelState.AddModelError("UserEmailContains", "Bu email daha önceden alınmış");
                    return(View());
                }
                else
                {
                    var user = _mapper.Map <User>(model);

                    _userBLL.AddUser(user);

                    return(View("Completed", model));
                }
            }
        }
Пример #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("********手写IOC容器*************");

            CustomIOCContainer container = new CustomIOCContainer();

            container.Register <IUserDAL, UserDAL>();
            container.Register <IUserBLL, UserBLL>();
            //单接口多实现
            container.Register <IMessageDAL, SmsDAL>("smsDAL");
            container.Register <IMessageDAL, EmailDAL>("emailDAL");
            container.Register <IStudentDAL, StudentDAL>();

            //解析
            IUserDAL    iuserDAL  = container.Resolve <IUserDAL>();
            IUserBLL    iuserBLL  = container.Resolve <IUserBLL>();//解析IUserBLL需要参数
            IMessageDAL ismsDAL   = container.Resolve <IMessageDAL>("smsDAL");
            IMessageDAL iemailDAL = container.Resolve <IMessageDAL>("emailDAL");

            //执行DAL方法
            iuserDAL.AddUser(new Wcs.Models.UserModel());

            //执行BLL方法
            iuserBLL.AddUser(new Wcs.Models.UserModel());

            //属性注入的方式--执行BLL方法
            iuserBLL.AddUser_Property(new Wcs.Models.UserModel());

            //方法注入的方式--执行BLL方法
            iuserBLL.AddUser_Method(new Wcs.Models.UserModel());

            //实现单接口多实现,注册或解析时要区分下字典里面的值,所以key加要shortName
            ismsDAL.Send();
            iemailDAL.Send();

            /*思考:单接口多实现如果在构造别的类的时候需要构造IMessageDAL,此时应该选择SmsDAL还是EmailDAL
             * 所以就要在构造函数里面用属性去指定shortName,用UserBLL做例子来实现
             * 在此还要引入一个新的知识点,参数也是可以打标记的(WcsParameterAttribute)
             */
            IUserBLL iuserBLL2 = container.Resolve <IUserBLL>();//解析IUserBLL需要参数

            /*
             * IOC+Aop 利用Castle手写实现
             */

            Console.WriteLine("*********************IOC+Aop 利用Castle手写实现*********************");
            IStudentDAL iStudentDAL = container.Resolve <IStudentDAL>();

            //用扩展方法实现Aop,这样对这个接口里面的所有的发方法都会前后加逻辑
            IStudentDAL istudentDAL_aop = (IStudentDAL)iStudentDAL.AOP(typeof(IStudentDAL));

            istudentDAL_aop.Study(new Wcs.Models.StudentModel()
            {
                Name = "张三"
            });
            istudentDAL_aop.Run(new Wcs.Models.StudentModel()
            {
                Name = "张三"
            });

            /*这样扩展出的Aop实现,有局限性,所有的逻辑就都会在IocIntercetor的方法里面
             * 为了更灵活,实现MVC过滤器的那样灵活,就要引入特性,请看 public static class AopExtend的AOP扩展方法
             */

            /*
             * AOP方法封装之后,可以直接和IOC融合,把CustomIOCContainer的Resolve方法返回实体的时候
             * 后面加上.AOP方法即可,这样整个框架就都支持AOP了,
             * 把上面调用AOP可以直接注释掉,在下面进行验证
             */
            iStudentDAL.Run(new Wcs.Models.StudentModel()
            {
                Name = "张三"
            });
        }
Пример #9
0
 /// <summary>
 /// 增加用户
 /// </summary>
 /// <param name="user">用户信息</param>
 /// <returns></returns>
 public JsonResult PostAddUser(UserInfo user)
 {
     return(userBLL.AddUser(user));
 }
        private void btn_OK_Click(object sender, EventArgs e)
        {
            bool isPassChanged = false;

            switch (CheckData())
            {
            case 0:
                MessageBox.Show("You must fill in all fields!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;

            case 1:
                MessageBox.Show("Invalid Phone Number!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case 2:
                MessageBox.Show("Invalid Email or Password!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case 3:
                MessageBox.Show("You must insert an image!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                break;

            case 4:
                string FileName = tb_Username.Text.Replace(" ", String.Empty) + ".Jpeg";
                userVM.UserName = tb_Username.Text.Replace(" ", String.Empty);
                if (tb_Password.Enabled)
                {
                    userVM.UserPassword = tb_Password.Text.Replace(" ", String.Empty);
                    isPassChanged       = true;
                }
                userVM.UserGmail = tb_Email.Text.Replace(" ", String.Empty);
                userVM.UserPhone = tb_Phone.Text.Replace(" ", String.Empty);
                if (rbtn_Male.Checked)
                {
                    userVM.UserGender = true;
                }
                else
                {
                    userVM.UserGender = false;
                }
                if (Change)
                {
                    UpdateIMG(FileName);
                }
                userVM.ListImg.Clear();
                userVM.ListImg.Add(TempAvatar);
                ///properties to check existed
                Dictionary <string, string> properties = new Dictionary <string, string>();
                properties.Add("phone", userVM.UserPhone);
                properties.Add("gmail", userVM.UserGmail);
                if (ID == 0)
                {
                    if (qLUserBLL.Checkexisted(properties))
                    {
                        qLUserBLL.AddUser(userVM);
                        MessageBox.Show("A new user has been successfully created!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        myDel();
                        this.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("Existed Email or Phone!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    properties.Add("code", userVM.UserCode);
                    if (qLUserBLL.Checkexisted(properties))
                    {
                        qLUserBLL.UpdateUser(userVM, listDel, isPassChanged);
                        MessageBox.Show("This user has been successfully updated!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        myDel();
                        this.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("Existed Email or Phone!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                break;

            default:
                break;
            }
        }
Пример #11
0
 public UserModelResponse AddUser(UserModelRequest entity)
 {
     //return new UserModelResponse { IsSuccess = true };
     return(userBLL.AddUser(entity));
 }