/// <summary>
 /// Deprecated Method for adding a new object to the Settings EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSettings(Setting setting)
 {
     base.AddObject("Settings", setting);
 }
Пример #2
0
        public MembershipCreateStatus bCreateUser(string CompanyName, string Username, string Password, string Email, string TaxCode, string Phone)
        {
            if (String.IsNullOrEmpty(CompanyName)) throw new ArgumentException("Value cannot be null or empty.", "CompanyName");
            if (String.IsNullOrEmpty(Username)) throw new ArgumentException("Value cannot be null or empty.", "UserName");
            if (String.IsNullOrEmpty(Email)) throw new ArgumentException("Value cannot be null or empty.", "Email");
            if (String.IsNullOrEmpty(Password)) throw new ArgumentException("Value cannot be null or empty.", "Password");

            MembershipCreateStatus status;

            var checkUser = from m in StoreDb.Webmasters
                            where (m.Username == Username)
                            select m;
            if (checkUser.Count() != 0)
            {
                status = MembershipCreateStatus.DuplicateUserName;
                return status;
            }
            var checkEmail = from m in StoreDb.Webmasters
                             where (m.Email == Email)
                             select m;
            if (checkEmail.Count() != 0)
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return status;
            }

            Webmaster web = new Webmaster();
            web.Username = Username;
            web.FirstName = CompanyName;
            web.CompanyName = CompanyName;
            web.Password = Password;
            web.Phone = Phone;
            web.Email = Email;
            web.Status = 0;
            web.DateJoin = DateTime.Now;
            web.AccountType = 1; //0 la personal account  1 la bussiness account
            web.TaxCode = TaxCode;

            string hash = MPHash.hash(Username + Password);
            web.VerifyCode = hash;

            StoreDb.Webmasters.AddObject(web);
            StoreDb.SaveChanges();

            status = MembershipCreateStatus.Success;

            //Tao bang Earning tuong ung
            var checknow = StoreDb.Webmasters.Single(m => m.Username == Username);

            Earning e = new Earning();
            e.Amount = 0;
            e.Currency = "VND";
            e.WebmasterId = checknow.Id;
            e.Status = 0;//keep money
            StoreDb.Earnings.AddObject(e);
            StoreDb.SaveChanges();

            //tao Role cho user nay
            string[] webmaster = new string[] { "Webmaster" };
            string[] user = new string[] { Username };
            MyRoleProvider role = new MyRoleProvider();
            role.AddUsersToRoles(user, webmaster);

            //tao Setting table cho webmaster nay
            int webmt = StoreDb.Webmasters.Single(w => w.Username == Username).Id;
            Setting set = new Setting();
            set.WebmasterId = webmt;
            set.Language = "EN";//default is EN
            StoreDb.Settings.AddObject(set);
            StoreDb.SaveChanges();


            return status;

        }
 /// <summary>
 /// Create a new Setting object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="webmasterId">Initial value of the WebmasterId property.</param>
 /// <param name="language">Initial value of the Language property.</param>
 public static Setting CreateSetting(global::System.Int32 id, global::System.Int32 webmasterId, global::System.String language)
 {
     Setting setting = new Setting();
     setting.Id = id;
     setting.WebmasterId = webmasterId;
     setting.Language = language;
     return setting;
 }