Exemple #1
0
        private async void frmUsers_Load(object sender, EventArgs e)
        {
            loadComboBoxes.loadRoles(cbRole, false);
            if (cbRole.Items.Count <= 0)
            {
                //MessageBox.error.
                //this.Close();
            }
            if (userId != null)
            {
                authUser = await apiService.GetById <Model.AuthUser>(userId);

                writeFields(authUser);

                var userImageList = await apiService_authUserImage.Get <List <Model.AuthUserImage> >(new AuthUserFaceSearchRequest()
                {
                    AuthUserId = (int)userId
                });

                if (userImageList.Count > 0)
                {
                    authUserImage = userImageList[0];
                    pbImage.Image = ByteToImage(authUserImage.AuthUserImage1);
                }
                pbQrCode.Image = ByteToImage(qRCodeHelper.GenerateQRCode(authUser.QrCode));
            }
        }
Exemple #2
0
        private async void Home_Load(object sender, EventArgs e)
        {
            // "HIDE" the form
            this.Opacity = 0;

            //making pb round
            //System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            //gp.AddEllipse(0, 0, pbUserImage.Width - 3, pbUserImage.Height - 3);
            //Region rg = new Region(gp);
            //pbUserImage.Region = rg;


            //loading user from db
            user = await apiService_user.GetById <Model.AuthUser>(userId);

            //loading user image
            var userImageList = await apiService_userImage.Get <List <Model.AuthUserImage> >(new Model.SearchRequest.AuthUserFaceSearchRequest()
            {
                AuthUserId = userId
            });

            userImage         = userImageList[0];
            pbUserImage.Image = ByteToImage(userImage.AuthUserImage1);

            //loading user full name
            lblUserName.Text = user.FirstName + " " + user.LastName;

            //report selected
            cbSearch.SelectedIndex = 0;

            // "SHOW" THE FORM
            this.Opacity = 100;
        }
Exemple #3
0
 private async void metroButton1_Click(object sender, EventArgs e)
 {
     var insert = new Model.AuthUserImage()
     {
         AuthUserImage1 = ImageToByte2(pbImage.Image), AuthUserId = 2020
     };
     await apiService_authUserImage.Insert <Model.AuthUserImage>(insert);
 }
Exemple #4
0
        public async Task <IActionResult> PutAuthUserImage(int id, Model.AuthUserImage insert)
        {
            try
            {
                var result = _mapper.Map <AuthUserImage>(insert);
                result.Id = id;
                _context.Entry(result).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AuthUserImageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #5
0
        public async Task <ActionResult <Model.AuthUserImage> > PostAuthUserImage(Model.AuthUserImage insert)
        {
            var result = _mapper.Map <AuthUserImage>(insert);

            try
            {
                _context.AuthUserImage.Add(result);

                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (AuthUserImageExists(result.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetAuthUserImage", new { id = result.Id }, result));
        }
Exemple #6
0
        private async void btnSubmit_Click(object sender, EventArgs e)
        {
            if (this.ValidateChildren())
            {
                //reading fields from form
                var user = readFields();
                //updating existing user
                if (userId != null)
                {
                    //updating user
                    user.QrCode = authUser.QrCode;
                    await apiService.Update <Model.AuthUser>(userId, user);

                    //updating user image
                    if (!string.IsNullOrEmpty(txtImageSource.Text))
                    {
                        var result = await apiService_authUserImage.Get <List <Model.AuthUserImage> >(new AuthUserFaceSearchRequest()
                        {
                            AuthUserId = authUser.Id
                        });

                        if (result.Count > 0)
                        {
                            var update = new Model.AuthUserImage()
                            {
                                AuthUserId = (int)userId, AuthUserImage1 = ImageToByte2(pbImage.Image)
                            };
                            await apiService_authUserImage.Update <Model.AuthUserImage>(result[0].Id, update);
                        }
                    }
                }
                else
                {
                    //generating new qr code until its unique
                    var findNewCode = true;
                    do
                    {
                        var qrCodeText        = qRCodeHelper.GenerateRandomString(15);
                        var userSearchRequest = new AuthUserSearchRequest()
                        {
                            qrCode = qrCodeText
                        };
                        var qrResult = await apiService.Get <List <Model.AuthUser> >(userSearchRequest);

                        findNewCode = qrResult.Count > 0;
                        if (findNewCode == false)
                        {
                            user.QrCode = qrCodeText;
                        }
                    } while (findNewCode == true);
                    //inserting new user into db
                    var result = await apiService.Insert <Model.AuthUser>(user);

                    //inserting new user image
                    var insert = new Model.AuthUserImage()
                    {
                        AuthUserId = (int)result.Id, AuthUserImage1 = ImageToByte2(pbImage.Image)
                    };
                    await apiService_authUserImage.Insert <Model.AuthUserImage>(insert);

                    //cutting and inserting face from image into db.
                    Image <Gray, byte> img1 = new Image <Gray, byte>((Bitmap)pbImage.Image);
                    var rect = detectFace(img1);
                    if (rect != null)
                    {
                        imageFaceFound = true;
                        var r = cutImage(img1, (Rectangle)rect);
                        Image <Gray, byte> img = r.Copy().Convert <Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.Inter.Cubic);
                        var insert1            = new Model.AuthUserFace()
                        {
                            AuthUserId = result.Id, Face = ImageToByte2(img.Bitmap)
                        };
                        var r1 = await apiService_authUserFace.Insert <object>(insert1);
                    }
                }
                this.Close();
            }
        }