private async Task <PantryViewModel> CreatePantryViewModelFromPantryAsync(Pantry pantry) { var pantryViewModel = new PantryViewModel { Id = pantry.Id, OwnerId = pantry.OwnerId }; foreach (var pantryItem in pantry.Items) { var pantryItemViewModel = new PantryItemViewModel { Id = pantryItem.Id, CatalogItemId = pantryItem.CatalogItemId }; var catalogItem = await _catalogItemRepository.GetAsync(pantryItem.CatalogItemId); pantryItemViewModel.ProductId = catalogItem.ProductId; pantryItemViewModel.ProductName = catalogItem.ProductName; pantryItemViewModel.ProductPictureUrl = catalogItem.ProductPictureUrl; pantryViewModel.Items.Add(pantryItemViewModel); } return(pantryViewModel); }
public async Task <IActionResult> AddFromPantryToTrolley(PantryItemViewModel pantryItemViewModel) { var trolleyViewModel = await GetTrolleyViewModelAsync(); await _trolleyManager.AddToTrolleyAsync(trolleyViewModel.Id, pantryItemViewModel.CatalogItemId, 1); return(RedirectToAction("Index")); }
private async Task <IActionResult> InsertOrUpdateItem(PantryItemViewModel item) { var insertOrUpdateItem = Mapper.Map <PantryItem>(item); if (await _pantryService.InsertOrUpdate(UserId, insertOrUpdateItem)) { return(Ok(Mapper.Map <PantryItemViewModel>(insertOrUpdateItem))); } return(Forbid("You do not have access to this pantry")); }
public async Task <IActionResult> UpdateItem([FromBody] PantryItemViewModel item) { try { return(await InsertOrUpdateItem(item)); } catch (Exception ex) { _logger.LogError(LoggingEvents.PANTRY_EDIT_ITEM, ex, $"Update item failed; user id - {UserId}; item - {JsonConvert.SerializeObject(item)}"); return(this.InternalServerError()); } }