public async Task <IActionResult> Create([Bind("Id,Name,Form,Requirement,Effect,Materials")] Craftable craftable) { if (ModelState.IsValid) { _itemRepository.InsertCraftable(craftable); await _itemRepository.Save(); return(RedirectToAction(nameof(Index))); } return(View(craftable)); }
public async Task <ActionResult <Craftable> > PostCraftable(Craftable craftable) { if (string.IsNullOrEmpty(craftable.Name) || string.IsNullOrEmpty (craftable.Requirement) || string.IsNullOrEmpty(craftable.Materials) || string.IsNullOrEmpty (craftable.Form) || string.IsNullOrEmpty(craftable.Effect)) { return(BadRequest()); } if (await _craftRepository.GetCraftable(craftable.Id) != null) { _craftRepository.UpdateCraftable(craftable); await _craftRepository.Save(); } _craftRepository.InsertCraftable(craftable); await _craftRepository.Save(); return(CreatedAtAction("GetCraftable", new { id = craftable.Id }, craftable)); }
private async Task GetItems() { try { // Get list of items from item API var items = await _itemService.GetAll(); if (items != null) { // Check each, to see if it already exists in DB foreach (var item in items) { var existItem = await _itemRepository.GetCraftableRef(item.Id); if (existItem != null) { // If it exists, update if needed, else continue loop if (item.Name.Equals(existItem.Name) && item.Requirement.Equals (existItem.Requirement) && item.Materials.Equals (existItem.Materials) && item.Effect.Equals(existItem.Effect) && item.Form.Equals (existItem.Form)) { continue; } else { var updItem = new Craftable { Effect = item.Effect, Form = item.Form, Id = existItem.Id, Materials = item.Materials, Name = item.Name, Requirement = item.Requirement }; _itemRepository.UpdateCraftable(updItem); } } else { // Item doesn't exist, create new var newItem = new Craftable { Name = item.Name, Requirement = item.Requirement, Materials = item.Materials, Effect = item.Effect, Form = item.Form, ItemRef = item.Id, Id = item.Id }; _itemRepository.InsertCraftable(newItem); } } await _itemRepository.Save(); } } catch (BrokenCircuitException) { _logger.LogWarning("Broken Circuit"); } }