Esempio n. 1
0
        public UserModel getUserById(string username)     // New
        {
            TTTV__UserInformation item = proxy.getUserInfoByID(username);

            if (item != null)
            {
                UserModel model = new UserModel();

                model.UserName = item.Username;
                model.SelectedDetailProvincesValue = item.ProvinceDetailID;
                model.SelectedDistrictValue        = item.DistrictID;
                model.SelectedProvinceValue        = item.ProvinceID;
                model.Tinh         = proxy.Tinh(item.ProvinceID);
                model.Quan         = proxy.Quan(item.ProvinceID, item.DistrictID);
                model.Phuong       = proxy.Phuong(item.ProvinceID, item.DistrictID, item.ProvinceDetailID);
                model.Companyname  = item.CompanyName;
                model.BusinessCode = item.BusinessCode;
                model.Phone        = item.Phone;
                model.Mobile       = item.Mobile;
                model.CMND         = item.PersonCode;
                model.Name         = item.UserFullName;
                model.Age          = item.Age;
                model.Address      = item.Address;
                model.subAddress   = item.SubAddress;
                return(model);
            }
            else
            {
                return(null);
            }
        }
        // Insert User vào Database.
        public void InsertUser(string username, string password, string email, int provinceID, int districtID, int detailprovinceID, int roleID, out MembershipCreateStatus status)
        {
            try
            {
                TTTV__Users           user = new TTTV__Users();
                TTTV__UserInformation info = new TTTV__UserInformation();

                user.Username         = username;
                user.Password         = password;
                user.Email            = email;
                user.RoleId           = roleID;
                info.Username         = username;
                info.ProvinceID       = provinceID;
                info.DistrictID       = districtID;
                info.ProvinceDetailID = detailprovinceID;
                db.TTTV__Users.AddObject(user);
                db.TTTV__UserInformation.AddObject(info);
                db.SaveChanges();
                status = MembershipCreateStatus.Success;
            }
            catch (Exception ex)
            {
                status = MembershipCreateStatus.ProviderError;
                throw ex;
            }
        }
        public TTTV__UserInformation getUserInfoByID(string user)
        {
            TTTV__UserInformation item = db.TTTV__UserInformation.Where(e => e.Username == user).Select(e => e).Single();

            if (item != null)
            {
                return(item);
            }
            return(null);
        }
        public void updateUserInfo(string UserName, string Companyname, string BusinessCode, string Phone, string Moblie, string CMND, string Name, int?Age, string Address, int province, int district, int detail, string email, int?role)
        {
            TTTV__UserInformation user  = db.TTTV__UserInformation.Single(e => e.Username == UserName);
            TTTV__Users           login = db.TTTV__Users.Single(e => e.Username == UserName);

            user.CompanyName  = Companyname;
            user.BusinessCode = BusinessCode;
            user.Phone        = Phone;
            user.Mobile       = Moblie;
            user.PersonCode   = CMND;
            user.UserFullName = Name;
            user.Age          = Age;
            login.RoleId      = role;
            login.Email       = email;
            db.SaveChanges();
        }
        public void InsertUser(string username, string password, string email, int provinceID, int districtID, int detailprovinceID, int roleID, string question, string answear, string companyname, string businesscode, string phone, string mobile, string CMND, string name, int age, string address, string subaddress, out MembershipCreateStatus status) // Tao user
        {
            try
            {
                TTTV__Users           user = new TTTV__Users();
                TTTV__UserInformation info = new TTTV__UserInformation();

                user.Username           = username;
                user.Password           = password;
                user.Email              = email;
                user.RoleId             = roleID;
                user.ForgotPassQuestion = question;
                user.ForgotPassAnswer   = answear;
                info.Username           = username;
                info.ProvinceID         = provinceID;
                info.DistrictID         = districtID;
                info.ProvinceDetailID   = detailprovinceID;
                info.CompanyName        = companyname;
                info.BusinessCode       = businesscode;
                info.Phone              = phone;
                info.Mobile             = mobile;
                info.PersonCode         = CMND;
                info.UserFullName       = name;
                info.Age        = age;
                info.Address    = address;
                info.SubAddress = subaddress;
                db.TTTV__Users.AddObject(user);
                db.TTTV__UserInformation.AddObject(info);
                db.SaveChanges();
                status = MembershipCreateStatus.Success;
            }
            catch (Exception ex)
            {
                CustomException cex = new CustomException();
                cex.Details = ex.Message;
                cex.Issue   = "Trùng tên đăng nhập";
                //status = MembershipCreateStatus.ProviderError;
                throw new FaultException <CustomException>(cex, new FaultReason(cex.Issue));
            }
        }