示例#1
0
        public async Task <UserResponse> CreateUser(User user)
        {
            bool UserCreated = false;

            sms.OpenPort(GC.SerialPortName, "9600");

            NIRA nira = new NIRA();

            if (user.NationalRegInfo.NIN != null)
            {
                if (nira.CheckPerson(user.NationalRegInfo.NIN))
                {
                    user.NationalRegInfo.ID = nira.GetPerson(user.NationalRegInfo.NIN);

                    if (await UserExists(user))
                    {
                        return(UserResponse.USEREXISTS);
                    }

                    else
                    {
                        Query = "CreateUser";

                        using (Con = new SqlConnection(GC.ConnectionString))
                        {
                            if (Con.State == ConnectionState.Closed)
                            {
                                Con.Open();
                            }
                            using (Com = new SqlCommand(Query, Con))
                            {
                                Com.CommandType = CommandType.StoredProcedure;

                                Com.Parameters.Add(new SqlParameter("@personid", user.NationalRegInfo.ID));
                                Com.Parameters.Add(new SqlParameter("@mail", user.Email));
                                Com.Parameters.Add(new SqlParameter("@UserName", user.UserName));
                                Com.Parameters.Add(new SqlParameter("@phonenumber", user.PhoneNumber));
                                Com.Parameters.Add(new SqlParameter("@pswd", user.Password));

                                Com.ExecuteNonQuery();

                                Com.Dispose();

                                UserCreated = true;

                                User RegisteredUser = new User();
                                RegisteredUser = await GetUser(user.NationalRegInfo.NIN);

                                try
                                {
                                    if (RegisteredUser.PhoneNumber != null)
                                    {
                                        sms.sendMsg(RegisteredUser.PhoneNumber, String.Format("Hello {0} {1}, \n Welcome to {3}. Please be sure that your car will always be safe in any of our registered parking Areas. \n Thank You", RegisteredUser.NationalRegInfo.FirstName, RegisteredUser.NationalRegInfo.LastName, GC.SystemTitle));
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }



                        return(UserResponse.SUCCESS);
                    }
                }


                else
                {
                    UserCreated = false;
                    return(UserResponse.NOTREGISTERED);
                }
            }
            else
            {
                if (nira.CheckPerson(new ImageConverter().ToBitmap(new ImageConverter().ToByteArr(user.NationalRegInfo.FingerPrint))))
                {
                    user.NationalRegInfo.ID = nira.GetPerson(new ImageConverter().ToBitmap(new ImageConverter().ToByteArr(user.NationalRegInfo.FingerPrint)));

                    if (await UserExists(user))
                    {
                        return(UserResponse.USEREXISTS);
                    }

                    else
                    {
                        Query = "CreateUser";

                        using (Con = new SqlConnection(GC.ConnectionString))
                        {
                            if (Con.State == ConnectionState.Closed)
                            {
                                Con.Open();
                            }
                            using (Com = new SqlCommand(Query, Con))
                            {
                                Com.CommandType = CommandType.StoredProcedure;

                                Com.Parameters.Add(new SqlParameter("@personid", user.NationalRegInfo.ID.ToString()));
                                Com.Parameters.Add(new SqlParameter("@mail", user.Email));
                                Com.Parameters.Add(new SqlParameter("@phonenumber", user.PhoneNumber));
                                Com.Parameters.Add(new SqlParameter("@pswd", user.Password));

                                Com.ExecuteNonQuery();

                                Com.Dispose();

                                UserCreated = true;

                                User RegisteredUser = new User();
                                RegisteredUser = await GetUser(user.NationalRegInfo.NIN);

                                try
                                {
                                    if (RegisteredUser.PhoneNumber != null)
                                    {
                                        sms.sendMsg(RegisteredUser.PhoneNumber, String.Format("Hello {0} {1}, \n Welcome to {3}. Please be sure that your car will always be safe in any of our registered parking Areas. \n Thank You", RegisteredUser.NationalRegInfo.FirstName, RegisteredUser.NationalRegInfo.LastName, GC.SystemTitle));
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }



                        return(UserResponse.SUCCESS);
                    }
                }
                else
                {
                    UserCreated = false;
                    return(UserResponse.NOTREGISTERED);
                }
            }
        }
示例#2
0
        public async Task <UserResponse> CreateUser(User user)
        {
            bool UserCreated = false;
            NIRA nira        = new NIRA();

            if (user.NationalRegInfo.NIN != null)
            {
                if (nira.CheckPerson(user.NationalRegInfo.NIN))
                {
                    user.NationalRegInfo.ID = nira.GetPerson(user.NationalRegInfo.NIN);

                    if (await UserExists(user))
                    {
                        return(UserResponse.USEREXISTS);
                    }

                    else
                    {
                        Query = "CreateUser";

                        using (Con = new SqlConnection(GC.ConnectionString))
                        {
                            if (Con.State == ConnectionState.Closed)
                            {
                                Con.Open();
                            }
                            using (Com = new SqlCommand(Query, Con))
                            {
                                Com.CommandType = CommandType.StoredProcedure;

                                Com.Parameters.Add(new SqlParameter("@personid", user.NationalRegInfo.ID));
                                Com.Parameters.Add(new SqlParameter("@mail", user.Email));
                                Com.Parameters.Add(new SqlParameter("@phonenumber", user.PhoneNumber));
                                Com.Parameters.Add(new SqlParameter("@pswd", user.Password));

                                Com.ExecuteNonQuery();

                                Com.Dispose();

                                UserCreated = true;
                            }
                        }

                        return(UserResponse.SUCCESS);
                    }
                }


                else
                {
                    UserCreated = false;
                    return(UserResponse.NOTREGISTERED);
                }
            }
            else
            {
                if (nira.CheckPerson(new ImageConverter().ToBitmap(new ImageConverter().ToByteArr(user.NationalRegInfo.FingerPrint))))
                {
                    user.NationalRegInfo.ID = nira.GetPerson(new ImageConverter().ToBitmap(new ImageConverter().ToByteArr(user.NationalRegInfo.FingerPrint)));

                    if (await UserExists(user))
                    {
                        return(UserResponse.USEREXISTS);
                    }

                    else
                    {
                        Query = "CreateUser";

                        using (Con = new SqlConnection(GC.ConnectionString))
                        {
                            if (Con.State == ConnectionState.Closed)
                            {
                                Con.Open();
                            }
                            using (Com = new SqlCommand(Query, Con))
                            {
                                Com.CommandType = CommandType.StoredProcedure;

                                Com.Parameters.Add(new SqlParameter("@personid", user.NationalRegInfo.ID.ToString()));
                                Com.Parameters.Add(new SqlParameter("@mail", user.Email));
                                Com.Parameters.Add(new SqlParameter("@phonenumber", user.PhoneNumber));
                                Com.Parameters.Add(new SqlParameter("@pswd", user.Password));

                                Com.ExecuteNonQuery();

                                Com.Dispose();

                                UserCreated = true;
                            }
                        }

                        return(UserResponse.SUCCESS);
                    }
                }
                else
                {
                    UserCreated = false;
                    return(UserResponse.NOTREGISTERED);
                }
            }
        }