/// <summary>
        ///  database connection for Registrion
        /// </summary>
        /// <param name="data"> store the Complete Employee information</param>
        /// <returns></returns>
        public async Task <bool> EmployeeRegister(EmployeeModel data)
        {
            try
            {
                SqlConnection connection = DatabaseConnection();
                //password encrption
                string Password = EncryptedPassword.EncodePasswordToBase64(data.Password);
                //for store procedure and connection to database
                SqlCommand command = StoreProcedureConnection("spUserRegister", connection);
                command.Parameters.AddWithValue("@EmployeeName", data.EmployeeName);
                command.Parameters.AddWithValue("@Username", data.Username);
                command.Parameters.AddWithValue("@Password", Password);
                command.Parameters.AddWithValue("@Gender", data.Gender);
                command.Parameters.AddWithValue("@City", data.City);
                command.Parameters.AddWithValue("@EmailID", data.EmailID);
                command.Parameters.AddWithValue("@Designation", data.Designation);
                command.Parameters.AddWithValue("@WorkingExperience", data.WorkingExperience);
                connection.Open();
                int Response = await command.ExecuteNonQueryAsync();

                connection.Close();
                if (Response != 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 public bool ParkingLogin(ParkingCL data)
 {
     try
     {
         SqlCommand command  = StoreProcedureConnection("spParkingLogin", connection);
         string     Password = EncryptedPassword.EncodePasswordToBase64(data.Password);
         command.Parameters.AddWithValue("@ParkingId", data.ParkingId);
         command.Parameters.AddWithValue("@Password", Password);
         connection.Open();
         int Response = command.ExecuteNonQuery();
         connection.Close();
         if (Response != 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
        /// <summary>
        ///   database connection for Login
        /// </summary>
        /// <param name="data"> Login API</param>
        /// <returns></returns>
        public async Task <int> EmployeeLogin(Login data)
        {
            try
            {
                SqlConnection connection = DatabaseConnection();
                //password encrption
                string     Password = EncryptedPassword.EncodePasswordToBase64(data.Password);
                SqlCommand command  = StoreProcedureConnection("splogin_pro", connection);
                command.Parameters.AddWithValue("@Username", data.Username);
                command.Parameters.AddWithValue("@Password", Password);
                command.Parameters.AddWithValue("@Designation", data.Designation);
                connection.Open();
                SqlDataReader reader = await command.ExecuteReaderAsync();

                int Status = 0;
                while (reader.Read())
                {
                    Status = reader.GetInt32(0);
                }
                connection.Close();
                if (Status == 1)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        ///  database connection for Registrion
        /// </summary>
        /// <param name="data"> store the Complete Employee information</param>
        /// <returns></returns>
        public async Task <bool> UserRegister(Usermodel data)
        {
            try
            {
                SqlConnection connection = DatabaseConnection();
                //password encrption
                string Password = EncryptedPassword.EncodePasswordToBase64(data.Password);
                //for store procedure and connection to database
                SqlCommand command = StoreProcedureConnection("spParkingUserRegister", connection);
                command.Parameters.AddWithValue("@FirstName", data.FirstName);
                command.Parameters.AddWithValue("@LastName", data.LastName);
                command.Parameters.AddWithValue("@EmailID", data.EmailID);
                command.Parameters.AddWithValue("@Password", Password);
                command.Parameters.AddWithValue("@UserRole", data.UserRole);
                command.Parameters.AddWithValue("@CreateDate", data.CreateDate);
                connection.Open();
                int Response = await command.ExecuteNonQueryAsync();

                connection.Close();
                if (Response != 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Exemple #5
0
        /// <summary>
        /// Checking for valid user using MailID and Password
        /// </summary>
        /// <param name="Info"></param>
        /// <returns></returns>
        public bool LoginVerification(Login Info)
        {
            try
            {
                bool input = Enum.TryParse <Driver>(Info.DriverCategory, true, out Driver driver);
                if (input != true)
                {
                    throw new Exception("Invalid Driver Category");
                }
                string MailID         = Info.MailID;
                string Password       = EncryptedPassword.EncodePasswordToBase64(Info.Password);    //Password Encrypted
                string DriverCategory = Info.DriverCategory;

                var Result = dBContext.Users.Where(u => u.MailID == MailID && u.Password == Password && u.DriverCategory == DriverCategory).FirstOrDefault();

                if (Result != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Exemple #6
0
        public UserDetails Registration(UserRegistration userRegistration)
        {
            UserDetails details = new UserDetails();

            try
            {
                string   connectoin = Configuration.GetConnectionString("MyConnection");
                DateTime createdDate;
                createdDate = DateTime.Now;
                using (SqlConnection sqlConnection = new SqlConnection(connectoin))
                {
                    string     Password   = EncryptedPassword.EncodePasswordToBase64(userRegistration.Password);
                    SqlCommand sqlCommand = new SqlCommand("SpAddUserDetails", sqlConnection);
                    sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
                    sqlCommand.Parameters.AddWithValue("@FirstName", userRegistration.FirstName);
                    sqlCommand.Parameters.AddWithValue("@LastName", userRegistration.LastName);
                    sqlCommand.Parameters.AddWithValue("@Email", userRegistration.Email);
                    sqlCommand.Parameters.AddWithValue("@Password", Password);
                    sqlCommand.Parameters.AddWithValue("@Address", userRegistration.Address);
                    sqlCommand.Parameters.AddWithValue("@City", userRegistration.City);
                    sqlCommand.Parameters.AddWithValue("@PhoneNumber", userRegistration.PhoneNumber);
                    sqlCommand.Parameters.AddWithValue("@CreatedDate", createdDate);
                    sqlConnection.Open();
                    SqlDataReader reader = sqlCommand.ExecuteReader();
                    Console.WriteLine("output=", reader);
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            details.UserId      = Convert.ToInt32(reader["UserId"].ToString());
                            details.FirstName   = reader["FirstName"].ToString();
                            details.LastName    = reader["LastName"].ToString();
                            details.UserRole    = reader["UserRole"].ToString();
                            details.Email       = reader["Email"].ToString();
                            details.Address     = reader["Address"].ToString();
                            details.City        = reader["City"].ToString();
                            details.PhoneNumber = reader["PhoneNumber"].ToString();
                        }
                    }
                    else
                    {
                        Console.WriteLine("No Data Found");
                    }
                    sqlConnection.Close();
                }
                return(details);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        //Method for User login
        public UserRegistration login(UserLogin user)
        {
            UserRegistration userLogin = new UserRegistration();

            try
            {
                //Connection string declared
                string connect = Configuration.GetConnectionString("MyConnection");

                //Password encrypted
                string Password = EncryptedPassword.EncodePasswordToBase64(user.Password);

                using (SqlConnection Connection = new SqlConnection(connect))
                {
                    SqlCommand sqlCommand = new SqlCommand("UserLogin", Connection);

                    sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
                    sqlCommand.Parameters.AddWithValue("@Email", user.Email);
                    sqlCommand.Parameters.AddWithValue("@Password", Password);

                    //connection open
                    Connection.Open();

                    //read data form the database
                    SqlDataReader reader = sqlCommand.ExecuteReader();

                    //While Loop For Reading status result from SqlDataReader.
                    while (reader.Read())
                    {
                        userLogin.UserId       = Convert.ToInt32(reader["UserId"].ToString());
                        userLogin.FirstName    = reader["FirstName"].ToString();
                        userLogin.LastName     = reader["LastName"].ToString();
                        userLogin.Gender       = reader["Gender"].ToString();
                        userLogin.Email        = reader["Email"].ToString();
                        userLogin.Address      = reader["Address"].ToString();
                        userLogin.Designation  = reader["Designation"].ToString();
                        userLogin.Salary       = Convert.ToDouble(reader["Salary"].ToString());
                        userLogin.MobileNumber = reader["MobileNumber"].ToString();
                        userLogin.Password     = reader["Password"].ToString();
                    }

                    //connection close
                    Connection.Close();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(userLogin);
        }
Exemple #8
0
        //Method to register user in the dataabase
        public UserDetails Registration(UserRegistration user)
        {
            UserDetails details = new UserDetails();

            try
            {
                //Connection string declared
                string connect = Configuration.GetConnectionString("MyConnection");

                //password encrypted
                string   Password = EncryptedPassword.EncodePasswordToBase64(user.Password);
                DateTime createdDate;
                createdDate = DateTime.Now;

                using (SqlConnection Connection = new SqlConnection(connect))
                {
                    SqlCommand sqlCommand = new SqlCommand("UserRegistration", Connection);
                    sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;

                    sqlCommand.Parameters.AddWithValue("@FirstName", user.FirstName);
                    sqlCommand.Parameters.AddWithValue("@LastName", user.LastName);
                    sqlCommand.Parameters.AddWithValue("@Email", user.Email);
                    sqlCommand.Parameters.AddWithValue("@Password", Password);
                    sqlCommand.Parameters.AddWithValue("@PhoneNumber", user.PhoneNumber);

                    //connection open
                    Connection.Open();

                    // Read data form database
                    SqlDataReader reader = sqlCommand.ExecuteReader();

                    //While Loop For Reading status result from SqlDataReader.
                    while (reader.Read())
                    {
                        details.UserId      = Convert.ToInt32(reader["id"].ToString());
                        details.FirstName   = reader["FirstName"].ToString();
                        details.LastName    = reader["LastName"].ToString();
                        details.Email       = reader["Email"].ToString();
                        details.PhoneNumber = reader["PhoneNumber"].ToString();
                    }

                    //connection close
                    Connection.Close();
                }
                return(details);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public int UpdateEmployee(ParkingCL data)
        {
            try
            {
                SqlCommand com      = StoreProcedureConnection("spUpdateParkingDetails", connection);
                string     Password = EncryptedPassword.EncodePasswordToBase64(data.Password);
                com.Parameters.AddWithValue("@ParkingId", data.ParkingId);
                com.Parameters.AddWithValue("VehicalNo", data.VehicalNo);
                com.Parameters.AddWithValue("VehicalBrand", data.VehicalBrand);
                com.Parameters.AddWithValue("VehicalColor", data.VehicalColor);
                if (data.ExitTime > data.EntryTime && data.ParkingType != "Own")
                {
                    data.ChargePerHr = CHARGE_PER_HR;
                }
                com.Parameters.AddWithValue("ChargePerHr", data.ChargePerHr);
                com.Parameters.AddWithValue("EntryTime", data.EntryTime);
                com.Parameters.AddWithValue("DriverCategory", data.DriverCategory);
                com.Parameters.AddWithValue("ParkingType", data.ParkingType);
                if (data.ExitTime < data.EntryTime)
                {
                    data.ExitTime = data.EntryTime;
                }
                com.Parameters.AddWithValue("ExitTime", data.ExitTime);
                com.Parameters.AddWithValue("@Password", Password);

                connection.Open();
                int Response = com.ExecuteNonQuery();
                connection.Close();
                if (Response == 0)
                {
                    return(0);
                }
                else
                {
                    return(1);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                connection.Close();
            }
        }
Exemple #10
0
 public bool ParkingRegisterDatails(ParkingUser Info)
 {
     try
     {
         string Encrypted = Info.Password;
         Info.Password = EncryptedPassword.EncodePasswordToBase64(Encrypted);
         var Result = Parking.ParkingRegisterDatails(Info);
         if (!Result.Equals(null))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Exemple #11
0
 /// <summary>
 /// Add Information to Register the user
 /// Return the status true ro false
 /// </summary>
 /// <param name="Info"></param>
 /// <returns></returns>
 public bool AddUser(Users Info)
 {
     try
     {
         string Encrypted = Info.Password;
         Info.Password = EncryptedPassword.EncodePasswordToBase64(Encrypted);            //Password get Encrypted
         var Result = User.AddUser(Info);
         if (!Result.Equals(null))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Exemple #12
0
 //method to register new user
 public UserRegistration register(UserRegistration user)
 {
     try
     {
         string Encrypted = user.Password;
         user.Password = EncryptedPassword.EncodePasswordToBase64(Encrypted);
         var Result = parkingLot.AddUser(user);
         if (!Result.Equals(null))
         {
             return(user);
         }
         else
         {
             throw new Exception("Not found");
         }
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
        //Method to update user record by id
        public object UpdateUserRecord(int UserId, UserRegistration details)
        {
            try
            {
                //variables declared
                string Email    = details.Email;
                string Password = EncryptedPassword.EncodePasswordToBase64(details.Password);

                //validating Email and Id
                var Validation = dbContext.UserDetails.Where(u => u.Email == Email && u.ID != UserId).FirstOrDefault();
                if (Validation != null)
                {
                    throw new Exception("User Already Exist");
                }

                //validating and updating user id records in the database
                var record = (from x in dbContext.UserDetails
                              where x.ID == UserId
                              select x).First();
                if (record != null)
                {
                    record.FirstName    = details.FirstName;
                    record.LastName     = details.LastName;
                    record.Email        = details.Email;
                    record.Password     = Password;
                    record.UserType     = details.UserType;
                    record.ModifiedDate = DateTime.Now;
                    dbContext.SaveChanges();
                    return(record);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
        /// <summary>
        ///   database connection for Login
        /// </summary>
        /// <param name="user"> Login API</param>
        /// <returns></returns>
        public UserDetails UserLogin(Login user)
        {
            UserDetails details = new UserDetails();

            try
            {
                SqlConnection connection = DatabaseConnection();
                //password encrption
                string     Password = EncryptedPassword.EncodePasswordToBase64(user.Password);
                SqlCommand command  = StoreProcedureConnection("spLogin", connection);
                command.Parameters.AddWithValue("@EmailID", user.EmailID);
                command.Parameters.AddWithValue("@Password", Password);

                connection.Open();

                //read data form the database
                SqlDataReader reader = command.ExecuteReader();


                //While Loop For Reading status result from SqlDataReader.
                while (reader.Read())
                {
                    details.ID        = Convert.ToInt32(reader["ID"].ToString());
                    details.FirstName = reader["FirstName"].ToString();
                    details.LastName  = reader["LastName"].ToString();
                    details.UserRole  = reader["UserRole"].ToString();
                    details.EmailID   = reader["EmailID"].ToString();
                }

                //connection close
                connection.Close();
                return(details);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemple #15
0
        public UserDetails Login(UserLogin user)
        {
            UserDetails details = new UserDetails();

            try
            {
                string connect = Configuration.GetConnectionString("MyConnection");
                //Password encrypted
                string Password = EncryptedPassword.EncodePasswordToBase64(user.Password);
                using (SqlConnection Connection = new SqlConnection(connect))
                {
                    SqlCommand sqlCommand = new SqlCommand("SpAddUserLogin", Connection);

                    sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
                    sqlCommand.Parameters.AddWithValue("@Email", user.Email);
                    sqlCommand.Parameters.AddWithValue("@Password", Password);
                    Connection.Open();
                    SqlDataReader reader = sqlCommand.ExecuteReader();
                    while (reader.Read())
                    {
                        details.UserId      = Convert.ToInt32(reader["UserId"].ToString());
                        details.FirstName   = reader["FirstName"].ToString();
                        details.LastName    = reader["LastName"].ToString();
                        details.UserRole    = reader["UserRole"].ToString();
                        details.Email       = reader["Email"].ToString();
                        details.Address     = reader["Address"].ToString();
                        details.City        = reader["City"].ToString();
                        details.PhoneNumber = reader["PhoneNumber"].ToString();
                    }
                    Connection.Close();
                }
                return(details);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemple #16
0
        public bool ParkingLoginDatails(Login Info)
        {
            try
            {
                string MailID   = Info.MailID;
                string Password = EncryptedPassword.EncodePasswordToBase64(Info.Password);

                var Result = dBContext.Users.Where(u => u.MailID == MailID && u.Password == Password).FirstOrDefault();

                if (Result != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Exemple #17
0
        public object UpdateUserRecord(Users Info, int ID)
        {
            try
            {
                string MailID     = Info.MailID;
                string Password   = EncryptedPassword.EncodePasswordToBase64(Info.Password);
                var    Validation = dBContext.Users.Where(u => u.MailID == MailID && u.ID != ID).FirstOrDefault();

                if (Validation != null)
                {
                    throw new Exception("User Already Exist ");
                }

                var Entries = (from x in dBContext.Users
                               where x.ID == ID
                               select x).First();
                if (Entries != null)
                {
                    Entries.FirstName      = Info.FirstName;
                    Entries.LastName       = Info.LastName;
                    Entries.MailID         = Info.MailID;
                    Entries.Password       = Password;
                    Entries.DriverCategory = Info.DriverCategory;
                    Entries.ModifiedDate   = DateTime.Now;
                    dBContext.SaveChanges();
                    return(Entries);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        public UserLogin Login(UserLogin user)
        {
            try
            {
                //validating UserType
                bool inputUserType = Enum.TryParse <UserTypes.User>(user.UserTypes, true, out UserTypes.User type);
                if (inputUserType != true)
                {
                    throw new Exception("Invalid User Category");
                }

                //variable declared
                string Email  = user.Email;
                int    UserId = user.UserId;

                //password encrypted
                string Password = EncryptedPassword.EncodePasswordToBase64(user.Password);

                //User category
                string UserType = user.UserTypes;

                //Validating Login details
                var Result = dbContext.UserDetails.Where(v => v.ID == UserId && v.Email == Email && v.Password == Password && v.UserType == UserType).FirstOrDefault();
                if (Result != null)
                {
                    return(user);
                }
                else
                {
                    throw new Exception("Login failed");
                }
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
        //Method to add user details
        public Response AddUserDetails(UserRegistration user)
        {
            Response response = new Response();

            try
            {
                //Connection string declared
                string connect = Configuration.GetConnectionString("MyConnection");

                //password encrypted
                string Password = EncryptedPassword.EncodePasswordToBase64(user.Password);

                using (SqlConnection Connection = new SqlConnection(connect))
                {
                    SqlCommand sqlCommand = new SqlCommand("UserRegistration", Connection);

                    sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;

                    sqlCommand.Parameters.AddWithValue("@FirstName", user.FirstName);
                    sqlCommand.Parameters.AddWithValue("@LastName", user.LastName);
                    sqlCommand.Parameters.AddWithValue("@Gender", user.Gender);
                    sqlCommand.Parameters.AddWithValue("@Email", user.Email);
                    sqlCommand.Parameters.AddWithValue("@Address", user.Address);
                    sqlCommand.Parameters.AddWithValue("@Designation", user.Designation);
                    sqlCommand.Parameters.AddWithValue("@Salary", user.Salary);
                    sqlCommand.Parameters.AddWithValue("@MobileNumber", user.MobileNumber);
                    sqlCommand.Parameters.AddWithValue("@Password", Password);

                    //connection open
                    Connection.Open();

                    //declare variable
                    int status = 0;

                    //Execute query
                    status = sqlCommand.ExecuteNonQuery();

                    try
                    {
                        SqlDataReader dataReader = sqlCommand.ExecuteReader();

                        while (dataReader.Read())
                        {
                            response.UserId       = Convert.ToInt32(dataReader["UserId"].ToString());
                            response.FirstName    = dataReader["FirstName"].ToString();
                            response.LastName     = dataReader["LastName"].ToString();
                            response.Gender       = dataReader["Gender"].ToString();
                            response.Email        = dataReader["Email"].ToString();
                            response.Address      = dataReader["Address"].ToString();
                            response.Designation  = dataReader["Designation"].ToString();
                            response.Salary       = Convert.ToDouble(dataReader["Salary"].ToString());
                            response.MobileNumber = dataReader["MobileNumber"].ToString();
                            response.Password     = dataReader["Password"].ToString();
                        }
                    }
                    catch
                    {
                        Response myReturnData = new Response()
                        {
                            message = "Error"
                        };
                        string json = JsonConvert.SerializeObject(myReturnData);
                    }

                    //connection close
                    Connection.Close();

                    //validation
                    if (status == 1)
                    {
                        response.status = "Valid Email";
                        response.data   = "Entered";
                    }
                    else
                    {
                        response.status = "Invalid Email";
                        response.data   = "Not entered";
                    }
                }
                return(response);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }