private async void LoadLookupAsync() { var items = await LookupRepository.GetItemsAsync(c => true); if (items.Item5.Count() == 0) { await LookupRepository.CreateItemAsync(new Lookup { Area = "Type", Key = "Contact", Value = "Contact" }); await LookupRepository.CreateItemAsync(new Lookup { Area = "Type", Key = "Customer", Value = "Customer" }); await LookupRepository.CreateItemAsync(new Lookup { Area = "Type", Key = "Lead", Value = "Lead" }); } }
public ActionResult Create(Contact contact) { try { // Note: Not necessary. Let CosmosDB set the ID contact.Id = null; // set the contact type contact.ContactType = DefaultContactType; // TODO: Add insert logic here if (!ModelState.IsValid) { throw new Exception(); } Repository.CreateItemAsync(contact); return(RedirectToAction(nameof(Index))); } catch (Exception e) { logger.LogError(e, "Contact id was not found", null); ViewBag.Area = Constants.ContactArea; return(View(contact)); } }
public async Task <IActionResult> Post([FromBody] Contact contact) { try { // Note: Not necessary. Let CosmosDB set the ID contact.Id = null; // TODO: Add insert logic here if (!ModelState.IsValid) { return(BadRequest()); } await Repository.CreateItemAsync(contact); } catch (Exception e) { Logger.LogError(e.ToString()); throw e; } return(Created(string.Empty, contact)); }