Esempio n. 1
0
        public bool updateUserInfo(int id, IuserDTO user)
        {
            int retVal;

            using (this.connection = DbProviderFactories.GetFactory(provider).CreateConnection())
            {
                using (DbDataAdapter tableAdapter = DbProviderFactories.GetFactory(provider).CreateDataAdapter())
                {
                    DbConnectionStringBuilder builder = new DbConnectionStringBuilder();
                    builder.ConnectionString         = this.connectionString;
                    this.connection.ConnectionString = builder.ConnectionString;
                    connection.Open();

                    DbCommand cmd = DbProviderFactories.GetFactory(provider).CreateCommand();
                    cmd.Connection  = this.connection;
                    cmd.CommandText = string.Format("UPDATE userInfo SET " +
                                                    "Name='{0}', Age={1}, Gender={2}, MarriageStatus={3}" +
                                                    " WHERE Id={4}", user.NAME, user.AGE, user.GENDER, user.MARRIAGESTATUS, id);
                    tableAdapter.UpdateCommand = cmd;
                    retVal = tableAdapter.UpdateCommand.ExecuteNonQuery();
                }
            }
            if (retVal == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public int insertUser(IuserDTO user)
        {
            Connect();
            DbCommand cmd = this.dfp.CreateCommand();
            string    sql = string.Format("INSERT INTO userInfo (Id,Name,Age,Gender,MarriageStatus)" +
                                          " VALUES(67,'{0}',{1},{2},{3})", user.NAME, user.AGE, user.GENDER, user.MARRIAGESTATUS);

            cmd.Connection  = this.connection;
            cmd.CommandText = sql;
            int rows = cmd.ExecuteNonQuery();

            if (rows != 1)
            {
                Disconnect();
                return(-1);
            }
            else
            {
                sql             = "SELECT ISNULL(@@IDENTITY,0)";
                cmd.CommandText = sql;
                int userID = int.Parse(cmd.ExecuteScalar().ToString());
                Disconnect();
                return(userID);
            }
        }
Esempio n. 3
0
 public int insertUser(IuserDTO user)
 {
     using (var database = new Company.Person.EntityFrameworkDAL.PersonEntities())
     {
         int maxID = (from row in database.userInfoes
                      select row.Id).Max();
         Person.EntityFrameworkDAL.userInfo newuser = new Person.EntityFrameworkDAL.userInfo();
         newuser.Id             = maxID + 1;
         newuser.Name           = user.NAME;
         newuser.MarriageStatus = user.MARRIAGESTATUS;
         newuser.Age            = user.AGE;
         newuser.Gender         = user.GENDER;
         database.userInfoes.Add(newuser);
         return(maxID + 1);
     }
 }
Esempio n. 4
0
        public IuserDTO ReadUser(int userID)
        {
            IuserDTO user = null;

            using (var database = new Company.Person.EntityFrameworkDAL.PersonEntities())
            {
                var result = (from row in database.userInfoes
                              where row.Id == userID
                              select row).FirstOrDefault();
                if (result != null)
                {
                    user                = new userDTO(result.Id);
                    user.NAME           = result.Name;
                    user.AGE            = result.Age;
                    user.GENDER         = result.Gender;
                    user.MARRIAGESTATUS = result.MarriageStatus;
                }
            }
            return(user);
        }
Esempio n. 5
0
        public bool updateUserInfo(int id, IuserDTO user)
        {
            bool isUpdated = false;

            using (var database = new Company.Person.EntityFrameworkDAL.PersonEntities())
            {
                var result = (from row in database.userInfoes
                              where row.Id == id
                              select row).FirstOrDefault();
                if (result != null)
                {
                    result.Name           = user.NAME;
                    result.Age            = user.AGE;
                    result.Gender         = user.GENDER;
                    result.MarriageStatus = user.MARRIAGESTATUS;
                    database.SaveChanges();
                    isUpdated = true;
                }
            }
            return(isUpdated);
        }
Esempio n. 6
0
        public int insertUser(IuserDTO user)
        {
            var retVal = default(int);

            using (this.connection = DbProviderFactories.GetFactory(provider).CreateConnection())
            {
                using (DbDataAdapter tableAdapter = DbProviderFactories.GetFactory(provider).CreateDataAdapter())
                {
                    DbConnectionStringBuilder builder = new DbConnectionStringBuilder();
                    builder.ConnectionString         = this.connectionString;
                    this.connection.ConnectionString = builder.ConnectionString;
                    connection.Open();
                    DbCommand cmd = DbProviderFactories.GetFactory(provider).CreateCommand();
                    cmd.Connection  = this.connection;
                    cmd.CommandText = string.Format("INSERT INTO userInfo (Name,Age,Gender,MarriageStatus)" +
                                                    " VALUES('{0}',{1},{2},{3})", user.NAME, user.AGE, user.GENDER, user.MARRIAGESTATUS);
                    tableAdapter.InsertCommand = cmd;
                    retVal = (int)tableAdapter.InsertCommand.ExecuteScalar();
                }
            }
            return(retVal);
        }
        public bool updateUserInfo(int id, IuserDTO user)
        {
            Connect();

            DbCommand cmd = this.dfp.CreateCommand();
            string    sql = string.Format("UPDATE userInfo SET " +
                                          "Name='{0}', Age={1}, Gender={2}, MarriageStatus={3}" +
                                          " WHERE Id={4}", user.NAME, user.AGE, user.GENDER, user.MARRIAGESTATUS, id);

            cmd.Connection  = this.connection;
            cmd.CommandText = sql;
            int rows = cmd.ExecuteNonQuery();

            Disconnect();
            if (rows == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            int    layerType = Convert.ToInt16(ConfigurationManager.AppSettings["layerType"]);
            string layer     = string.Empty;
            string layerDLL  = string.Empty;

            switch (layerType)
            {
            case 1:
                layer    = DLLConstants.PersonDALConnectedType;
                layerDLL = DLLConstants.PersonConnectedDALDll;
                break;

            case 2:
                layer    = DLLConstants.PersonDALDisconnectedType;
                layerDLL = DLLConstants.PersonDisconnectedDALDll;
                break;

            case 3:
                layer    = DLLConstants.PersonDALEntityFramework;
                layerDLL = DLLConstants.PersonEntityFrameworkDALDll;
                break;
            }
            IAgreementBLL BLLref = UserRepository(layer, layerDLL);

            char again = 'y';

            while (again == 'y')
            {
                System.Console.WriteLine(MessageConstants.options);
                int option = 0;
                while (option < 1 || option > 6)
                {
                    bool success = Int32.TryParse(System.Console.ReadLine(), out option);
                    if (success == false)
                    {
                        System.Console.WriteLine(MessageConstants.inputInt);
                    }
                    else if (option < 1 || option > 6)
                    {
                        System.Console.WriteLine(MessageConstants.rangeInput);
                    }
                }

                switch (option)
                {
                case 1:
                    int id = 0;
                    System.Console.WriteLine("Enter the Id of the User");
                    int.TryParse(System.Console.ReadLine(), out id);
                    IuserDTO user = BLLref.ReadUser(id);
                    System.Console.WriteLine(user);
                    System.Console.WriteLine("------------------------------------");

                    break;

                case 2:
                    IList <IuserDTO> IList = BLLref.readAllUser();
                    foreach (userDTO u in IList)
                    {
                        System.Console.WriteLine(u);
                        System.Console.WriteLine("------------------------------------");
                    }
                    break;

                case 3:
                    userDTO newUser = new userDTO();
                    System.Console.WriteLine("Enter the name of the user");
                    newUser.NAME = System.Console.ReadLine();
                    System.Console.WriteLine("Enter the Age of the user");
                    newUser.AGE = int.Parse(System.Console.ReadLine());
                    System.Console.WriteLine("Enter the Gender of the user 1:Male 0:Female");
                    newUser.GENDER = int.Parse(System.Console.ReadLine());
                    System.Console.WriteLine("Enter the MaritalStatus of the user 1:Married 0:Single");
                    newUser.MARRIAGESTATUS = int.Parse(System.Console.ReadLine());
                    int userId = BLLref.insertUser(newUser);
                    System.Console.WriteLine("Id of the new user is : " + userId);
                    System.Console.WriteLine("------------------------------------");
                    break;

                case 4:
                    System.Console.WriteLine("Enter the Id of the user to delete");
                    int deleteId = int.Parse(System.Console.ReadLine());
                    if (BLLref.deleteUser(deleteId))
                    {
                        System.Console.WriteLine("User Deleted");
                    }
                    else
                    {
                        System.Console.WriteLine("Such user does not exist");
                    }
                    System.Console.WriteLine("------------------------------------");
                    break;

                case 5:
                    System.Console.WriteLine("Enter the Id of the user to Update");
                    int     updateId   = int.Parse(System.Console.ReadLine());
                    userDTO updateUser = new userDTO();
                    System.Console.WriteLine("Enter the newname of the user");
                    updateUser.NAME = System.Console.ReadLine();
                    System.Console.WriteLine("Enter the newAge of the user");
                    updateUser.AGE = int.Parse(System.Console.ReadLine());
                    System.Console.WriteLine("Enter the newGender of the user 1:Male 0:Female");
                    updateUser.GENDER = int.Parse(System.Console.ReadLine());
                    System.Console.WriteLine("Enter the newMaritalStatus of the user 1:Married 0:Single");
                    updateUser.MARRIAGESTATUS = int.Parse(System.Console.ReadLine());
                    if (BLLref.updateUserInfo(updateId, updateUser))
                    {
                        System.Console.WriteLine("Information updated");
                    }
                    else
                    {
                        System.Console.WriteLine("Such user does not exist");
                    }

                    System.Console.WriteLine("------------------------------------");

                    break;

                case 6:
                    System.Environment.Exit(0);
                    break;
                }
                System.Console.WriteLine(MessageConstants.again);

                char.TryParse(System.Console.ReadLine(), out again);
                again = char.ToLower(again);
            }
            System.Console.ReadLine();
        }
Esempio n. 9
0
 public bool updateUserInfo(int id, IuserDTO user)
 {
     return(DALref.updateUserInfo(id, user));
 }
Esempio n. 10
0
 public int insertUser(IuserDTO user)
 {
     return(DALref.insertUser(user));
 }