[TestCategory("Quarantine")] // Not currently working with emulator
        public async Task CreateDropAutoscaleContainerStreamApi()
        {
            DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync(
                Guid.NewGuid().ToString());

            ThroughputResponse databaseThroughput = await database.ReadThroughputIfExistsAsync(requestOptions : null);

            Assert.IsNotNull(databaseThroughput);
            Assert.AreEqual(HttpStatusCode.NotFound, databaseThroughput.StatusCode);

            string streamContainerId = Guid.NewGuid().ToString();

            using (ResponseMessage response = await database.CreateContainerStreamAsync(
                       new ContainerProperties(streamContainerId, "/pk"),
                       ThroughputProperties.CreateAutoscaleThroughput(5000)))
            {
                Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);

                ContainerInternal  streamContainer   = (ContainerInlineCore)database.GetContainer(streamContainerId);
                ThroughputResponse autoscaleIfExists = await streamContainer.ReadThroughputIfExistsAsync(
                    requestOptions : null,
                    default(CancellationToken));

                Assert.IsNotNull(autoscaleIfExists);
                Assert.AreEqual(5000, autoscaleIfExists.Resource.AutoscaleMaxThroughput);
            }
        }
        [TestCategory("Quarantine")] // Not currently working with emulator
        public async Task CreateDropAutoscaleContainer()
        {
            DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync(
                Guid.NewGuid().ToString());

            ContainerInternal container = (ContainerInlineCore)await database.CreateContainerAsync(
                new ContainerProperties(Guid.NewGuid().ToString(), "/pk"),
                ThroughputProperties.CreateAutoscaleThroughput(5000));

            Assert.IsNotNull(container);

            ThroughputResponse throughputResponse = await container.ReadThroughputAsync(requestOptions : null);

            Assert.IsNotNull(throughputResponse);
            Assert.AreEqual(5000, throughputResponse.Resource.AutoscaleMaxThroughput);

            throughputResponse = await container.ReplaceThroughputAsync(
                ThroughputProperties.CreateAutoscaleThroughput(6000),
                requestOptions : null,
                cancellationToken : default(CancellationToken));

            Assert.IsNotNull(throughputResponse);
            Assert.AreEqual(6000, throughputResponse.Resource.AutoscaleMaxThroughput);

            await database.DeleteAsync();
        }
        public async Task EncryptionBulkCrud()
        {
            TestDoc docToReplace = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt);

            docToReplace.NonSensitive = Guid.NewGuid().ToString();
            docToReplace.Sensitive    = Guid.NewGuid().ToString();

            TestDoc docToUpsert = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt);

            docToUpsert.NonSensitive = Guid.NewGuid().ToString();
            docToUpsert.Sensitive    = Guid.NewGuid().ToString();

            TestDoc docToDelete = await EncryptionTests.CreateItemAsync(EncryptionTests.itemContainerCore, EncryptionTests.dekId, TestDoc.PathsToEncrypt);

            (string endpoint, string authKey) = TestCommon.GetAccountInfo();
            CosmosClient clientWithBulk = new CosmosClientBuilder(endpoint, authKey)
                                          .WithEncryptor(EncryptionTests.encryptor)
                                          .WithBulkExecution(true)
                                          .Build();

            DatabaseInternal  databaseWithBulk  = (DatabaseInlineCore)clientWithBulk.GetDatabase(EncryptionTests.databaseCore.Id);
            ContainerInternal containerWithBulk = (ContainerInlineCore)databaseWithBulk.GetContainer(EncryptionTests.itemContainer.Id);

            List <Task> tasks = new List <Task>();

            tasks.Add(EncryptionTests.CreateItemAsync(containerWithBulk, EncryptionTests.dekId, TestDoc.PathsToEncrypt));
            tasks.Add(EncryptionTests.UpsertItemAsync(containerWithBulk, TestDoc.Create(), EncryptionTests.dekId, TestDoc.PathsToEncrypt, HttpStatusCode.Created));
            tasks.Add(EncryptionTests.ReplaceItemAsync(containerWithBulk, docToReplace, EncryptionTests.dekId, TestDoc.PathsToEncrypt));
            tasks.Add(EncryptionTests.UpsertItemAsync(containerWithBulk, docToUpsert, EncryptionTests.dekId, TestDoc.PathsToEncrypt, HttpStatusCode.OK));
            tasks.Add(EncryptionTests.DeleteItemAsync(containerWithBulk, docToDelete));
            await Task.WhenAll(tasks);
        }
        public async Task CreateDropAutoscaleAutoUpgradeDatabase()
        {
            DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync(
                nameof(CreateDropAutoscaleAutoUpgradeDatabase) + Guid.NewGuid(),
                ThroughputProperties.CreateAutoscaleThroughput(
                    maxAutoscaleThroughput: 5000,
                    autoUpgradeMaxThroughputIncrementPercentage: 10));

            // Container is required to validate database throughput upgrade scenarios
            Container container = await database.CreateContainerAsync("Test", "/id");

            ThroughputResponse autoscale = await database.ReadThroughputAsync(requestOptions : null);

            Assert.IsNotNull(autoscale);
            Assert.AreEqual(5000, autoscale.Resource.AutoscaleMaxThroughput);
            Assert.AreEqual(10, autoscale.Resource.AutoUpgradeMaxThroughputIncrementPercentage);

            ThroughputResponse autoscaleReplaced = await database.ReplaceThroughputAsync(
                ThroughputProperties.CreateAutoscaleThroughput(6000));

            Assert.IsNotNull(autoscaleReplaced);
            Assert.AreEqual(6000, autoscaleReplaced.Resource.AutoscaleMaxThroughput);
            Assert.IsNull(autoscaleReplaced.Resource.AutoUpgradeMaxThroughputIncrementPercentage);

            ThroughputResponse autoUpgradeReplace = await database.ReplaceThroughputAsync(
                ThroughputProperties.CreateAutoscaleThroughput(
                    maxAutoscaleThroughput: 7000,
                    autoUpgradeMaxThroughputIncrementPercentage: 20));

            Assert.IsNotNull(autoUpgradeReplace);
            Assert.AreEqual(7000, autoUpgradeReplace.Resource.AutoscaleMaxThroughput);
            Assert.AreEqual(20, autoUpgradeReplace.Resource.AutoUpgradeMaxThroughputIncrementPercentage);

            await database.DeleteAsync();
        }
        public async Task CreateDropFixedDatabase()
        {
            DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync(
                nameof(CreateDropAutoscaleDatabase) + Guid.NewGuid().ToString(),
                ThroughputProperties.CreateManualThroughput(5000));

            ThroughputResponse fixedDatabaseThroughput = await database.ReadThroughputAsync(requestOptions : null);

            Assert.IsNotNull(fixedDatabaseThroughput);
            Assert.AreEqual(5000, fixedDatabaseThroughput.Resource.Throughput);
            Assert.IsNull(fixedDatabaseThroughput.Resource.AutoscaleMaxThroughput);
            Assert.IsNull(fixedDatabaseThroughput.Resource.AutoUpgradeMaxThroughputIncrementPercentage);

            ThroughputResponse fixedReplaced = await database.ReplaceThroughputAsync(
                ThroughputProperties.CreateManualThroughput(6000));

            Assert.IsNotNull(fixedReplaced);
            Assert.AreEqual(6000, fixedReplaced.Resource.Throughput);
            Assert.IsNull(fixedReplaced.Resource.AutoscaleMaxThroughput);
            Assert.IsNull(fixedReplaced.Resource.AutoUpgradeMaxThroughputIncrementPercentage);

            ThroughputResponse fixedReplacedIfExists = await database.ReplaceThroughputPropertiesIfExistsAsync(
                ThroughputProperties.CreateManualThroughput(7000));

            Assert.IsNotNull(fixedReplacedIfExists);
            Assert.AreEqual(7000, fixedReplacedIfExists.Resource.Throughput);
            Assert.IsNull(fixedReplacedIfExists.Resource.AutoscaleMaxThroughput);
            Assert.IsNull(fixedReplacedIfExists.Resource.AutoUpgradeMaxThroughputIncrementPercentage);

            await database.DeleteAsync();
        }
Ejemplo n.º 6
0
        public async Task DatabaseContractTest()
        {
            DatabaseResponse response = await this.CreateDatabaseHelper();

            Assert.IsNotNull(response);
            Assert.IsTrue(response.RequestCharge > 0);
            Assert.IsNotNull(response.Headers);
            Assert.IsNotNull(response.Headers.ActivityId);

            DatabaseProperties databaseSettings = response.Resource;

            Assert.IsNotNull(databaseSettings.Id);
            Assert.IsNotNull(databaseSettings.ResourceId);
            Assert.IsNotNull(databaseSettings.ETag);
            Assert.IsTrue(databaseSettings.LastModified.HasValue);
            Assert.IsTrue(databaseSettings.LastModified.Value > new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), databaseSettings.LastModified.Value.ToString());

            DatabaseInternal databaseCore = response.Database as DatabaseInlineCore;

            Assert.IsNotNull(databaseCore);
            Assert.IsNotNull(databaseCore.LinkUri);
            Assert.IsFalse(databaseCore.LinkUri.ToString().StartsWith("/"));

            response = await response.Database.DeleteAsync(cancellationToken : this.cancellationToken);

            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
        }
        public async Task CreateDropAutoscaleDatabaseStreamApi()
        {
            string databaseId = Guid.NewGuid().ToString();

            using (ResponseMessage response = await this.cosmosClient.CreateDatabaseStreamAsync(
                       new DatabaseProperties(databaseId),
                       ThroughputProperties.CreateAutoscaleThroughput(5000)))
            {
                Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            }

            DatabaseInternal   database  = (DatabaseInlineCore)this.cosmosClient.GetDatabase(databaseId);
            ThroughputResponse autoscale = await database.ReadThroughputAsync(requestOptions : null);

            Assert.IsNotNull(autoscale);
            Assert.AreEqual(5000, autoscale.Resource.AutoscaleMaxThroughput);

            ThroughputResponse autoscaleReplaced = await database.ReplaceThroughputAsync(
                ThroughputProperties.CreateAutoscaleThroughput(10000));

            Assert.IsNotNull(autoscaleReplaced);
            Assert.AreEqual(10000, autoscaleReplaced.Resource.AutoscaleMaxThroughput);

            await database.DeleteAsync();
        }
Ejemplo n.º 8
0
        public ActionResult CreateProduct(CreateProduct viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError("", Resources.Resource.CreateSPFail);

                    return(View("CreateProduct", viewModel));
                }
                if (string.IsNullOrEmpty(viewModel.SanPham.Tensp))
                {
                    ModelState.AddModelError("SanPham.Tensp", Resources.Resource.TenspCannotBeBlank);
                    return(View("CreateProduct", viewModel));
                }

                if (double.IsNaN(viewModel.SanPham.Gia))
                {
                    ModelState.AddModelError("SanPham.Gia", Resources.Resource.GiaCannotBeBlank);
                    return(View("CreateProduct", viewModel));
                }

                if (string.IsNullOrEmpty(viewModel.SanPham.MoTaSP))
                {
                    ModelState.AddModelError("SanPham.MoTaSP", Resources.Resource.MoTaSPCannotBeBlank);
                    return(View("CreateProduct", viewModel));
                }

                if (string.IsNullOrEmpty(viewModel.SanPham.Anh))
                {
                    ModelState.AddModelError("SanPham.Anh", Resources.Resource.AnhCannotBeBlank);
                    return(View("CreateProduct", viewModel));
                }

                string Result = DatabaseInternal.Insert_Product(viewModel.SanPham);

                if (Result == "Sản phẩm bị trùng.Xin mời nhập lại.")
                {
                    ModelState.AddModelError("", Resources.Resource.SanPhamAlreadyExists);

                    return(View("Creat", viewModel));
                }
                else if (Result == "Create Product Failed")
                {
                    ModelState.AddModelError("", Resources.Resource.CreateSPFail);

                    return(View("CreateProduct", viewModel));
                }



                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                LogFile.Error(ex.ToString());       // Ghi thông tin ra file
            }
            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 9
0
 public ActionResult FindProduct(ListProductViewModel viewModel)
 {
     try
     {
         viewModel.ListProducts           = DatabaseInternal.GetListProduct(new ListProductViewModel());
         viewModel.CurrentListProductType = DatabaseInternal.GetListProduct(viewModel);
         //CCallApi.GetTemplateAsync(CConfig.ListProduct+ "?Tensp=aaaa");
     }
     catch (Exception ex)
     {
         LogFile.Error(ex.ToString());   // Ghi thông tin ra file
     }
     return(View(viewModel));
 }
Ejemplo n.º 10
0
 public ActionResult DeleteProduct(int ID)
 {
     try
     {
         if (!DatabaseInternal.DeleteProduct(ID))
         {
         }
     }
     catch (Exception ex)
     {
         LogFile.Error(ex.ToString());   // Ghi thông tin ra file
     }
     return(RedirectToAction("Index", "Home"));
 }
Ejemplo n.º 11
0
        public async Task UserTests(bool directMode)
        {
            CosmosClient     client     = directMode ? DirectCosmosClient : GatewayCosmosClient;
            DatabaseInternal database   = (DatabaseInlineCore)client.GetDatabase(DatabaseId);
            List <string>    createdIds = new List <string>();

            try
            {
                UserResponse userResponse = await database.CreateUserAsync("BasicQueryUser1");

                createdIds.Add(userResponse.User.Id);

                userResponse = await database.CreateUserAsync("BasicQueryUser2");

                createdIds.Add(userResponse.User.Id);

                userResponse = await database.CreateUserAsync("BasicQueryUser3");

                createdIds.Add(userResponse.User.Id);

                //Read All
                List <UserProperties> results = await this.ToListAsync(
                    database.GetUserQueryStreamIterator,
                    database.GetUserQueryIterator <UserProperties>,
                    null,
                    CosmosBasicQueryTests.RequestOptions
                    );

                CollectionAssert.IsSubsetOf(createdIds, results.Select(x => x.Id).ToList());

                //Basic query
                List <UserProperties> queryResults = await this.ToListAsync(
                    database.GetUserQueryStreamIterator,
                    database.GetUserQueryIterator <UserProperties>,
                    "SELECT * FROM T where STARTSWITH(T.id, \"BasicQueryUser\")",
                    CosmosBasicQueryTests.RequestOptions
                    );

                CollectionAssert.AreEquivalent(createdIds, queryResults.Select(x => x.Id).ToList());
            }
            finally
            {
                foreach (string id in createdIds)
                {
                    await database.GetUser(id).DeleteAsync();
                }
            }
        }
Ejemplo n.º 12
0
        public ActionResult UpdateProduct(CreateProduct viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError("", Resources.Resource.UpdateFail);
                    //viewmodel.Companies = Database.GetListCompany();
                    viewModel.SP = DatabaseProduct.Lay_DS_SanPham();
                    return(View("EditUser", viewModel));
                }
                if (string.IsNullOrEmpty(viewModel.SanPham.Tensp))
                {
                    ModelState.AddModelError("SanPham.Tensp", Resources.Resource.TenspCannotBeBlank);
                    return(View("EditUser", viewModel));
                }

                if (double.IsNaN(viewModel.SanPham.Gia))
                {
                    ModelState.AddModelError("SanPham.Gia", Resources.Resource.GiaCannotBeBlank);
                    return(View("EditUser", viewModel));
                }

                if (string.IsNullOrEmpty(viewModel.SanPham.MoTaSP))
                {
                    ModelState.AddModelError("SanPham.MoTaSP", Resources.Resource.MoTaSPCannotBeBlank);
                    return(View("EditUser", viewModel));
                }

                if (string.IsNullOrEmpty(viewModel.SanPham.Anh))
                {
                    ModelState.AddModelError("SanPham.Anh", Resources.Resource.AnhCannotBeBlank);
                    return(View("EditUser", viewModel));
                }

                if (DatabaseInternal.UpdateProductInfo(viewModel.SanPham))
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            catch (Exception ex)
            {
                LogFile.Error(ex.ToString());   // Ghi thông tin ra file
            }
            ModelState.AddModelError("", Resources.Resource.UpdateFail);
            return(View("EditUser", viewModel));
        }
        [TestCategory("Quarantine")] // Not currently working with emulator
        public async Task ReadFixedWithAutoscaleTests()
        {
            DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync(
                Guid.NewGuid().ToString());

            ContainerInternal autoscaleContainer = (ContainerInlineCore)await database.CreateContainerAsync(
                new ContainerProperties(Guid.NewGuid().ToString(), "/pk"),
                ThroughputProperties.CreateAutoscaleThroughput(5000));

            Assert.IsNotNull(autoscaleContainer);

            // Reading a autoscale container with fixed results
            int?throughput = await autoscaleContainer.ReadThroughputAsync();

            Assert.IsNotNull(throughput);

            await database.DeleteAsync();
        }
        [TestCategory("Quarantine")] // Not currently working with emulator
        public async Task ContainerAutoscaleIfExistsTest()
        {
            DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync(
                nameof(CreateDropAutoscaleDatabase) + Guid.NewGuid().ToString());

            Container container = await database.CreateContainerAsync(
                containerProperties : new ContainerProperties("Test", "/id"),
                throughputProperties : ThroughputProperties.CreateAutoscaleThroughput(5000));

            ContainerInternal containerCore = (ContainerInlineCore)container;

            ThroughputResponse throughputResponse = await database.ReadThroughputIfExistsAsync(requestOptions : null);

            Assert.IsNotNull(throughputResponse);
            Assert.AreEqual(HttpStatusCode.NotFound, throughputResponse.StatusCode);
            Assert.IsNull(throughputResponse.Resource);

            throughputResponse = await database.ReplaceThroughputPropertiesIfExistsAsync(
                ThroughputProperties.CreateAutoscaleThroughput(6000));

            Assert.IsNotNull(throughputResponse);
            Assert.AreEqual(HttpStatusCode.NotFound, throughputResponse.StatusCode);
            Assert.IsNull(throughputResponse.Resource);

            throughputResponse = await containerCore.ReadThroughputIfExistsAsync(
                requestOptions : null,
                default(CancellationToken));

            Assert.IsNotNull(throughputResponse);
            Assert.IsTrue(throughputResponse.Resource.Throughput > 400);
            Assert.AreEqual(5000, throughputResponse.Resource.AutoscaleMaxThroughput);

            throughputResponse = await containerCore.ReplaceThroughputIfExistsAsync(
                ThroughputProperties.CreateAutoscaleThroughput(6000),
                requestOptions : null,
                default(CancellationToken));

            Assert.IsNotNull(throughputResponse);
            Assert.IsTrue(throughputResponse.Resource.Throughput > 400);
            Assert.AreEqual(6000, throughputResponse.Resource.AutoscaleMaxThroughput);

            await database.DeleteAsync();
        }
        public static async Task ClassInitialize(TestContext context)
        {
            EncryptionTests.dekProvider = new CosmosDataEncryptionKeyProvider(new TestKeyWrapProvider());
            EncryptionTests.encryptor   = new TestEncryptor(EncryptionTests.dekProvider);

            EncryptionTests.client       = EncryptionTests.GetClient();
            EncryptionTests.databaseCore = (DatabaseInlineCore)await EncryptionTests.client.CreateDatabaseAsync(Guid.NewGuid().ToString());

            EncryptionTests.keyContainer = await EncryptionTests.databaseCore.CreateContainerAsync(Guid.NewGuid().ToString(), "/id", 400);

            await EncryptionTests.dekProvider.InitializeAsync(EncryptionTests.databaseCore, EncryptionTests.keyContainer.Id);


            EncryptionTests.itemContainer = await EncryptionTests.databaseCore.CreateContainerAsync(Guid.NewGuid().ToString(), "/PK", 400);

            EncryptionTests.itemContainerCore = (ContainerInlineCore)EncryptionTests.itemContainer;

            EncryptionTests.dekProperties = await EncryptionTests.CreateDekAsync(EncryptionTests.dekProvider, EncryptionTests.dekId);
        }
        public async Task CreateDropAutoscaleDatabase()
        {
            DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync(
                nameof(CreateDropAutoscaleDatabase) + Guid.NewGuid().ToString(),
                ThroughputProperties.CreateAutoscaleThroughput(5000));

            ThroughputResponse autoscale = await database.ReadThroughputAsync(requestOptions : null);

            Assert.IsNotNull(autoscale);
            Assert.AreEqual(5000, autoscale.Resource.AutoscaleMaxThroughput);

            ThroughputResponse autoscaleReplaced = await database.ReplaceThroughputAsync(
                ThroughputProperties.CreateAutoscaleThroughput(10000));

            Assert.IsNotNull(autoscaleReplaced);
            Assert.AreEqual(10000, autoscaleReplaced.Resource.AutoscaleMaxThroughput);

            await database.DeleteAsync();
        }
Ejemplo n.º 17
0
        public async Task DatabaseAutoscaleIfExistsTest()
        {
            DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync(
                nameof(CreateDropAutoscaleDatabase) + Guid.NewGuid().ToString(),
                ThroughputProperties.CreateAutoscaleThroughput(5000));

            Container container = await database.CreateContainerAsync("Test", "/id");

            ContainerInternal containerCore = (ContainerInlineCore)container;

            ThroughputResponse throughputResponse = await database.ReadThroughputIfExistsAsync(requestOptions : null);

            Assert.IsNotNull(throughputResponse);
            Assert.AreEqual(5000, throughputResponse.Resource.AutoscaleMaxThroughput);

            throughputResponse = await database.ReplaceThroughputAsync(
                ThroughputProperties.CreateAutoscaleThroughput(6000));

            Assert.IsNotNull(throughputResponse);
            Assert.AreEqual(6000, throughputResponse.Resource.AutoscaleMaxThroughput);

            throughputResponse = await containerCore.ReadThroughputIfExistsAsync(
                requestOptions : null,
Ejemplo n.º 18
0
        public ActionResult CreateUser(CreateUserViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError("", Resources.Resource.CreateUserFail);

                    return(View("CreateUser", viewModel));
                }
                if (string.IsNullOrEmpty(viewModel.Users.UserName))
                {
                    ModelState.AddModelError("Users.UserName", Resources.Resource.UsernameCannotBeBlank);
                    return(View("CreateUser", viewModel));
                }

                if (string.IsNullOrEmpty(viewModel.Users.FullName))
                {
                    ModelState.AddModelError("Users.FullName", Resources.Resource.FullnameCannotBeBlank);
                    return(View("CreateUser", viewModel));
                }

                if (string.IsNullOrEmpty(viewModel.Users.Email))
                {
                    ModelState.AddModelError("Users.Email", Resources.Resource.EmailCannotBeBlank);
                    return(View("CreateUser", viewModel));
                }
                Regex regexEmail = new Regex(@"(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}\b");
                if (!regexEmail.IsMatch(viewModel.Users.Email))
                {
                    ModelState.AddModelError("Users.Email", Resources.Resource.EmailInvalid);
                    return(View("CreateUser", viewModel));
                }
                if (string.IsNullOrEmpty(viewModel.Users.Phone))
                {
                    ModelState.AddModelError("Users.Phone", Resources.Resource.PhoneCannotBeBlank);
                    return(View("CreateUser", viewModel));
                }
                //Regex regexPhone = new Regex(@"(09|03[2|6|8|9])+([0-9]{8})\b");
                //if (!regexPhone.IsMatch(viewModel.Users.Phone))
                //{
                //    ModelState.AddModelError("Users.Phone", Resources.Resource.PhoneInvalid);
                //    return View("CreateUser", viewModel);
                //}
                //if (string.IsNullOrEmpty(viewModel.Users.Note))
                //{
                //    ModelState.AddModelError("Users.Note", Resources.Resource.NoteCannotBeBlank);
                //    return View("CreateUser", viewModel);
                //}

                viewModel.Users.Password = ApplicationConfig.DefaultPassword;
                //viewmodel.Users.CompanyID = 196; // nhân viên mặc định mã chứng khoán là FTS

                //if (/*viewModel/*.IsActive*/*/)
                //{
                //    viewModel.Users.Active = ApplicationConfig.Active;
                //}
                //else
                //    viewModel.Users.Active = ApplicationConfig.InActive;

                //SystemLog log = new SystemLog()
                //{
                //    Action = "Tạo người dùng",
                //    Username = ((Users)Session[ApplicationConfig.UserInfo]).UserName,
                //    ErrorCode = "CREATEU00",
                //    MSG = ": " + viewModel.Users.UserName
                //};
                string Result = DatabaseInternal.Insert_User(viewModel.Users);

                if (Result == "Username bị trùng.Xin mời nhập lại.")
                {
                    //log.ErrorCode = "CREATEU02";
                    //Database.InsertLog(log);
                    //ModelState.AddModelError("", Resources.Resource.AccountAlreadyExists);

                    return(View("CreateUser", viewModel));
                }
                else if (Result == "Create User Failed")
                {
                    //log.ErrorCode = "CREATEU01";
                    //Database.InsertLog(log);
                    //ModelState.AddModelError("", Resources.Resource.CreateUserFail);

                    return(View("CreateUser", viewModel));
                }

                //Database.InsertLog(log);
                return(View("CreateUser", viewModel));
            }
            catch (Exception ex)
            {
                LogFile.Error(ex.ToString());   // Ghi thông tin ra file
            }
            return(View("CreateUser", viewModel));
        }
        public async Task ContainerBuilderAutoscaleTest()
        {
            DatabaseInternal database = (DatabaseInlineCore)await this.cosmosClient.CreateDatabaseAsync(
                nameof(CreateDropAutoscaleDatabase) + Guid.NewGuid().ToString());

            {
                Container container = await database.DefineContainer("Test", "/id")
                                      .CreateAsync(throughputProperties: ThroughputProperties.CreateAutoscaleThroughput(5000));

                ThroughputProperties throughputProperties = await container.ReadThroughputAsync(requestOptions : null);

                Assert.IsNotNull(throughputProperties);
                Assert.IsTrue(throughputProperties.Throughput > 400);
                Assert.AreEqual(5000, throughputProperties.AutoscaleMaxThroughput);
            }

            {
                Container container2 = await database.DefineContainer("Test2", "/id")
                                       .CreateIfNotExistsAsync(throughputProperties: ThroughputProperties.CreateAutoscaleThroughput(5000));

                ThroughputProperties throughputProperties = await container2.ReadThroughputAsync(requestOptions : null);

                Assert.IsNotNull(throughputProperties);
                Assert.IsTrue(throughputProperties.Throughput > 400);
                Assert.AreEqual(5000, throughputProperties.AutoscaleMaxThroughput);


                container2 = await database.DefineContainer(container2.Id, "/id")
                             .CreateIfNotExistsAsync(throughputProperties: ThroughputProperties.CreateAutoscaleThroughput(5000));

                throughputProperties = await container2.ReadThroughputAsync(requestOptions : null);

                Assert.IsNotNull(throughputProperties);
                Assert.IsTrue(throughputProperties.Throughput > 400);
                Assert.AreEqual(5000, throughputProperties.AutoscaleMaxThroughput);
            }

            {
                Container container3 = await database.DefineContainer("Test3", "/id")
                                       .CreateAsync(throughputProperties: ThroughputProperties.CreateManualThroughput(500));

                ThroughputProperties throughputProperties = await container3.ReadThroughputAsync(requestOptions : null);

                Assert.IsNotNull(throughputProperties);
                Assert.IsNull(throughputProperties.AutoscaleMaxThroughput);
                Assert.AreEqual(500, throughputProperties.Throughput);

                container3 = await database.DefineContainer(container3.Id, "/id")
                             .CreateIfNotExistsAsync(throughputProperties: ThroughputProperties.CreateManualThroughput(500));

                throughputProperties = await container3.ReadThroughputAsync(requestOptions : null);

                Assert.IsNotNull(throughputProperties);
                Assert.IsNull(throughputProperties.AutoscaleMaxThroughput);
                Assert.AreEqual(500, throughputProperties.Throughput);
            }

            {
                Container container4 = await database.DefineContainer("Test4", "/id")
                                       .CreateIfNotExistsAsync(throughputProperties: ThroughputProperties.CreateManualThroughput(500));

                ThroughputProperties throughputProperties = await container4.ReadThroughputAsync(requestOptions : null);

                Assert.IsNotNull(throughputProperties);
                Assert.IsNull(throughputProperties.AutoscaleMaxThroughput);
                Assert.AreEqual(500, throughputProperties.Throughput);
            }

            await database.DeleteAsync();
        }