public async Task <IActionResult> Index()
        {
            CustomerRegModel customerRegModel = new CustomerRegModel();

            customerRegModel.customerRegModelsList = await this.GetCustomersListAsync();

            return(View(customerRegModel));
        }
示例#2
0
 public async Task <string> UpdateCustomer([FromBody] CustomerRegModel customerRegModel)
 {
     try
     {
         CoonectCosmosDB();
         await this.ReplaceCustomerDocument(customerRegModel.id, customerRegModel);
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
     return("success");
 }
示例#3
0
 public async Task <string> CustomerRegisterAsync([FromBody] CustomerRegModel customerRegModel)
 {
     try
     {
         CoonectCosmosDB();
         await this.CreateDocumentIfNotExists(customerRegModel);
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
     return("success");
 }
示例#4
0
 /// <summary>
 /// CreateDocumentIfNotExists
 /// </summary>
 /// <param name="databaseName"></param>
 /// <param name="collectionName"></param>
 /// <param name="customerRegModel"></param>
 /// <returns></returns>
 private async Task CreateDocumentIfNotExists(CustomerRegModel customerRegModel)
 {
     try
     {
         await this.client.ReadDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collectionName, customerRegModel.id));
     }
     catch (DocumentClientException de)
     {
         if (de.StatusCode == HttpStatusCode.NotFound)
         {
             await this.client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), customerRegModel);
         }
         else
         {
             throw;
         }
     }
 }
        public async Task <ActionResult> RegisterAsync(CustomerRegModel customerRegModel)
        {
            try
            {
                if (string.IsNullOrEmpty(customerRegModel.id))
                {
                    #region Save
                    customerRegModel.id = customerRegModel.FirstName + "_" + DateTime.Now.TimeOfDay.Milliseconds;
                    var customerData = JsonConvert.SerializeObject(customerRegModel);
                    var buffer       = System.Text.Encoding.UTF8.GetBytes(customerData);
                    var byteData     = new ByteArrayContent(buffer);
                    byteData.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    HttpClient client = new HttpClient();
                    client.BaseAddress = new Uri(URL);
                    var response = await client.PostAsync("CustomerRegister", byteData);

                    client.Dispose();
                    #endregion
                }
                else
                {
                    #region Update
                    var customerData = JsonConvert.SerializeObject(customerRegModel);
                    var buffer       = System.Text.Encoding.UTF8.GetBytes(customerData);
                    var byteData     = new ByteArrayContent(buffer);
                    byteData.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    HttpClient client = new HttpClient();
                    client.BaseAddress = new Uri(URL);
                    var response = await client.PostAsync("UpdateCustomer", byteData);

                    client.Dispose();
                    #endregion
                }

                return(RedirectToAction("Index", "Home"));
                // return View("Index", new CustomerRegModel());
            }
            catch (Exception)
            {
                return(View("Index", customerRegModel));
            }
        }
示例#6
0
 private async Task ReplaceCustomerDocument(string CustomerId, CustomerRegModel updateCustomer)
 {
     await this.client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collectionName, CustomerId), updateCustomer);
 }