public async Task <IActionResult> Index() { CustomerRegModel customerRegModel = new CustomerRegModel(); customerRegModel.customerRegModelsList = await this.GetCustomersListAsync(); return(View(customerRegModel)); }
public async Task <string> UpdateCustomer([FromBody] CustomerRegModel customerRegModel) { try { CoonectCosmosDB(); await this.ReplaceCustomerDocument(customerRegModel.id, customerRegModel); } catch (Exception ex) { return(ex.Message); } return("success"); }
public async Task <string> CustomerRegisterAsync([FromBody] CustomerRegModel customerRegModel) { try { CoonectCosmosDB(); await this.CreateDocumentIfNotExists(customerRegModel); } catch (Exception ex) { return(ex.Message); } return("success"); }
/// <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)); } }
private async Task ReplaceCustomerDocument(string CustomerId, CustomerRegModel updateCustomer) { await this.client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collectionName, CustomerId), updateCustomer); }