コード例 #1
0
        public async Task <IActionResult> UpdateSecurity(int id, SecurityDTO SecurityDTO)
        {
            SecurityDTO.SecurityId = id;
            var response = await _Security.UpdateAsync(SecurityDTO);

            return(Ok(response));
        }
コード例 #2
0
        private void FormLogin_Load(object sender, EventArgs e)
        {
            if (IsNewUser == false)
            {
                LoginBL.SetCurrentUser(UserId);
                Text = "Edit usrers info";

                tbLogin.Text     = LoginBL.CurrentUser.Mail;
                tbFirstName.Text = LoginBL.CurrentUser.FirstName;
                tbLastName.Text  = LoginBL.CurrentUser.LastName;
                // LoginBL.CurrentUser.RoleId = 4;
                string gen = LoginBL.CurrentUser.Gender.Replace(" ", "");
                if (gen == "Male")
                {
                    rbMale.Checked   = true;
                    rbFemale.Checked = false;
                }
                else
                {
                    rbMale.Checked   = false;
                    rbFemale.Checked = true;
                }
                tbAdress.Text   = LoginBL.CurrentUser.Address;
                tbTel.Text      = LoginBL.CurrentUser.Tel;
                tbBankCard.Text = LoginBL.CurrentUser.BankCard;

                SecurityDTO sd = UsersBL.GetSecurityForUser(LoginBL.CurrentUser);

                tbPassword.Text        = sd.Password;
                tbKeyWord.Text         = sd.KeyWord;
                tbReenterPassword.Text = sd.Password;

                pbImage.Image = LoginBL.GetImageBinaryFromDb(LoginBL.CurrentUser.Id.ToString());
            }
        }
コード例 #3
0
        public SecurityDTO ToDTO(SecurityEntity model)
        {
            SecurityDTO dto = new SecurityDTO();

            dto.ID         = model.ID;
            dto.Question   = model.Question;
            dto.CreateTime = model.CreateTime;
            return(dto);
        }
コード例 #4
0
ファイル: SecurityController.cs プロジェクト: raulfe/Sween
        public async Task <IActionResult> InsertUser(SecurityDTO security)
        {
            var data = _mapper.Map <Security>(security);
            await _securityService.RegisterUser(data);

            security = _mapper.Map <SecurityDTO>(data);
            var response = new ApiResponse <SecurityDTO>(security);

            return(Ok(response));
        }
コード例 #5
0
        public async Task <IActionResult> Post(SecurityDTO securityDTO)
        {
            var security = _mapper.Map <Security>(securityDTO);

            security.Password = _passwordService.Hash(security.Password);

            await _securityService.RegisterUser(security);

            return(Ok());
        }
コード例 #6
0
        public async Task <IActionResult> Post(SecurityDTO securityDto)
        {
            var security = _mapper.Map <Security>(securityDto);

            security.Password = _passwordService.Hash(security.Password);

            await _securityService.RegisterUser(security);

            securityDto = _mapper.Map <SecurityDTO>(security);
            var response = new ApiResponse <SecurityDTO>(securityDto);

            return(Ok(response));
        }
コード例 #7
0
        public async Task <IActionResult> Create(SecurityDTO _securityDTO)
        {
            var security = mapper.Map <Security>(_securityDTO);

            security.Password = passwordService.Hash(_securityDTO.Password);

            await securityService.RegisterUser(security);

            var securityDTO = mapper.Map <SecurityDTO>(security);

            var response = new ApiResponse <SecurityDTO>(securityDTO);

            return(Ok());
        }
コード例 #8
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (IsNewUser)
            {
                LoginBL.CurrentUser = new UserDTO();
            }

            LoginBL.CurrentUser.Mail      = tbLogin.Text;
            LoginBL.CurrentUser.FirstName = tbFirstName.Text;
            LoginBL.CurrentUser.LastName  = tbLastName.Text;
            LoginBL.CurrentUser.RoleId    = 4;
            if (rbMale.Checked)
            {
                LoginBL.CurrentUser.Gender = "Male";
            }
            else
            {
                LoginBL.CurrentUser.Gender = "Female";
            }
            LoginBL.CurrentUser.Address  = tbAdress.Text;
            LoginBL.CurrentUser.Tel      = tbTel.Text;
            LoginBL.CurrentUser.BankCard = tbBankCard.Text;


            SecurityDTO sd = new SecurityDTO();


            sd.KeyWord = tbKeyWord.Text;
            sd.UserId  = LoginBL.CurrentUser.Id;
            if (tbPassword.Text != tbReenterPassword.Text)
            {
                MessageBox.Show("Paswwords not equel!");
                return;
            }

            sd.Password = tbPassword.Text;


            if (IsNewUser == false)
            {
                LoginBL.UpdateUser(LoginBL.CurrentUser, sd, pbImage.ImageLocation);
            }

            else
            {
                LoginBL.CreateNewUser(LoginBL.CurrentUser, sd, pbImage.ImageLocation);
            }
            Close();
        }
コード例 #9
0
        public static void UpdateUser(UserDTO u, SecurityDTO s, string i)
        {
            if (Dal == null)
            {
                Dal = new UserDAL(connStr);
            }

            u.Id        = CurrentUser.Id;
            CurrentUser = Dal.UpdateUser(u);
            s.UserId    = CurrentUser.Id;
            Dal.UpdatePasswordForUser(s);
            if (!String.IsNullOrEmpty(i))
            {
                Dal.PutImageBinaryInDb(i, s.UserId);
            }
        }
コード例 #10
0
        public static bool CreateNewUser(UserDTO u, SecurityDTO s, string i)
        {
            if (Dal == null)
            {
                Dal = new UserDAL(connStr);
            }

            CurrentUser = Dal.CreateUser(u);
            s.UserId    = CurrentUser.Id;
            Dal.SetPasswordForUser(s);
            if (!String.IsNullOrEmpty(i))
            {
                Dal.PutImageBinaryInDb(i, s.UserId);
            }
            return(true);
        }
コード例 #11
0
        public bool ChekPassword(UserDTO user, string password)
        {
            using (SqlConnection conn = new SqlConnection(this.connectionString))
                using (SqlCommand comm = conn.CreateCommand())

                {
                    comm.CommandText = String.Format("SELECT [Password] FROM [Security] Where UserId = {0} ", user.Id);
                    conn.Open();
                    SqlDataReader reader = comm.ExecuteReader();
                    SecurityDTO   sec    = new SecurityDTO();;
                    if (reader.Read())
                    {
                        sec.Password = reader["Password"].ToString();
                    }
                    if (sec.Password == password)
                    {
                        return(true);
                    }
                }

            return(false);
        }
コード例 #12
0
        public SecurityDTO GetSecurityForUser(UserDTO userDTO)/// + add loginName +///
        {
            SecurityDTO res = null;

            using (SqlConnection conn = new SqlConnection(this.connectionString))
                using (SqlCommand comm = conn.CreateCommand())
                {
                    comm.CommandText = String.Format("Select * from Security where [UserId] = {0}", userDTO.Id);
                    conn.Open();
                    SqlDataReader reader = comm.ExecuteReader();
                    if (reader.Read())
                    {
                        res             = new SecurityDTO();
                        res.Id          = Convert.ToInt32(reader["Id"].ToString());
                        res.Password    = reader["Password"].ToString();
                        res.KeyWord     = reader["KeyWord"].ToString();
                        res.IsTemporary = Convert.ToBoolean(reader["IsTemporary"].ToString());
                        res.ExpiredDate = Convert.ToDateTime(reader["ExpiredDate"].ToString());
                    }

                    return(res);
                }
        }
コード例 #13
0
        public SecurityDTO UpdatePasswordForUser(SecurityDTO s)
        {
            using (SqlConnection conn = new SqlConnection(this.connectionString))
                using (SqlCommand comm = conn.CreateCommand())
                {
                    comm.CommandText = "UPDATE[dbo].[Security]  SET [UserId] = @UserId ,[Password] = @Password ,[KeyWord] = @KeyWord ,[IsTemporary] = @IsTemporary ,[ExpiredDate] = @ExpiredDate  WHERE UserId = @UserId";
                    comm.Parameters.Clear();
                    comm.Parameters.AddWithValue("@Id", s.Id);
                    comm.Parameters.AddWithValue("@UserId", s.UserId);
                    comm.Parameters.AddWithValue("@Password", s.Password);
                    comm.Parameters.AddWithValue("@KeyWord", s.KeyWord);
                    comm.Parameters.AddWithValue("@IsTemporary", s.IsTemporary);
                    if (s.IsTemporary == false)
                    {
                        s.ExpiredDate = DateTime.Now;
                    }
                    comm.Parameters.AddWithValue("@ExpiredDate", s.ExpiredDate);
                    conn.Open();


                    s.Id = Convert.ToInt32(comm.ExecuteScalar());
                }
            return(s);
        }
コード例 #14
0
        public SecurityDTO SetPasswordForUser(SecurityDTO s)/// + add loginName +///
        {
            using (SqlConnection conn = new SqlConnection(this.connectionString))
                using (SqlCommand comm = conn.CreateCommand())
                {
                    comm.CommandText = "insert into Security (UserId,Password, KeyWord, IsTemporary,ExpiredDate) output INSERTED.Id values (@UserId,@Password, @KeyWord, @IsTemporary,@ExpiredDate)";
                    comm.Parameters.Clear();
                    comm.Parameters.AddWithValue("@Id", s.Id);
                    comm.Parameters.AddWithValue("@UserId", s.UserId);
                    comm.Parameters.AddWithValue("@Password", s.Password);
                    comm.Parameters.AddWithValue("@KeyWord", s.KeyWord);
                    comm.Parameters.AddWithValue("@IsTemporary", s.IsTemporary);
                    if (s.IsTemporary == false)
                    {
                        s.ExpiredDate = DateTime.Now;
                    }
                    comm.Parameters.AddWithValue("@ExpiredDate", s.ExpiredDate);
                    conn.Open();


                    s.Id = Convert.ToInt32(comm.ExecuteScalar());
                }
            return(s);
        }
コード例 #15
0
        public async Task <IActionResult> AddSecurity(SecurityDTO SecurityDTO)
        {
            var response = await _Security.AddAsync(SecurityDTO);

            return(Ok(response));
        }
コード例 #16
0
        static void Main(string[] args)
        {
            string      connStr     = "Data Source=DESKTOP-KHVC2BC;Initial Catalog=PZ_K;Integrated Security=True";
            UserDAL     dal         = new UserDAL(connStr);
            UserDTO     currentUser = null;
            SecurityDTO security    = null;

            char menuItem;
            char menuUpdateItem;


            //dal.PutImageBinaryInDb(@"G:\Project Kyrs\Kyrsova_PZ\Images\1.jpg", 4);

            while (true)
            {
                ShowMenuItems();
                menuItem = char.Parse(Console.ReadLine());

                switch (menuItem)
                {
                case 'l':
                    foreach (UserDTO cUser in dal.GetAllUsers())
                    {
                        Console.WriteLine(cUser.GetInfo());
                    }
                    break;

                case 'f':

                    Console.Write("Enter Id : ");
                    int iD;
                    Int32.TryParse(Console.ReadLine(), out iD);
                    currentUser = dal.GetUserById(iD);
                    Console.WriteLine(currentUser.GetInfo());

                    break;

                case 'u':

                    Console.Write("Enter Id : ");
                    int id;

                    Int32.TryParse(Console.ReadLine(), out id);
                    currentUser = dal.GetUserById(id);
                    if (currentUser != null)
                    {
                        Console.WriteLine(currentUser.GetInfo());

                        ShowMenuUpdateItems();

                        while (true)
                        {
                            menuUpdateItem = Console.ReadLine()[0];
                            switch (menuUpdateItem)
                            {
                            case '1':
                                Console.Write("Enter FirstName : ");
                                currentUser.FirstName = Console.ReadLine();
                                break;

                            case '2':

                                Console.Write("Enter LastName : ");
                                currentUser.LastName = Console.ReadLine();
                                break;

                            case '3':
                                Console.Write("Enter Gender : ");
                                currentUser.Gender = Console.ReadLine();
                                break;

                            case '4':
                                Console.Write("Enter Address : ");
                                currentUser.Address = Console.ReadLine();
                                break;

                            case '5':
                                Console.Write("Enter Mail : ");
                                currentUser.Mail = Console.ReadLine();
                                break;

                            case '6':
                                Console.Write("Enter Tel : ");
                                currentUser.Tel = Console.ReadLine();
                                break;

                            case '7':
                                Console.Write("Enter BankCard : ");
                                currentUser.BankCard = Console.ReadLine();
                                break;


                            case '8':
                                Console.Write("Path to images : ");
                                string path = Console.ReadLine();
                                if (dal.PutImageBinaryInDb(path, id) == false)
                                {
                                    Console.WriteLine("File not found");
                                }
                                break;

                            case '9':

                                Console.Write("Securuty Info : ");
                                security = new SecurityDTO();
                                Console.Write("Password :"******"KeyWord :");
                                security.KeyWord     = Console.ReadLine();
                                security.IsTemporary = false;

                                security.UserId = currentUser.Id;
                                dal.SetPasswordForUser(security);
                                break;
                            }
                            Console.WriteLine("For save and exit press e ");

                            menuUpdateItem = Console.ReadLine()[0];
                            if (menuUpdateItem == 'e')
                            {
                                dal.UpdateUser(currentUser);

                                break;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("User not found");
                    }

                    break;

                case 'e':
                    return;
                }

                Console.WriteLine("Pres any key to continue");
                Console.ReadKey();
            }



            //UserDTO m = new UserDTO
            //{
            //    Name = "Petro Inkognito",
            //    Mail = "*****@*****.**",
            //    Gender = "Male",
            //    Address= "LVIv"
            //};

            //dal.CreateUser(m);
            //m = manager.AddMovie(m);
        }