public async Task Update(FoodEditInfo foodEditInfo) { var food = new Domain.Food { ID = foodEditInfo.Id, Name = foodEditInfo.Name, Price = foodEditInfo.Price, FoodType = foodEditInfo.FoodType, Description = foodEditInfo.Description }; _db.Entry(food).State = EntityState.Modified; await _db.SaveChangesAsync(); _logger.LogInformation($"Food by Id [{food.ID}] Updated.", food); }
public async Task <Domain.API.FoodApiModel> MapFoodToApiModel(Domain.Food food) { this.Food = food; var foodApiModel = new FoodApiModel() { Currency = this.Food.Currency.ToString(), Description = this.Food.Description, Id = this.Food.Id, Name = this.Food.Name, Price = this.Food.Price, CreatedOn = this.Food.CreatedOn, Pictures = this.Food.Pictures != null?this.Food.Pictures.Select(m => m.FileName).ToList() : new List <string>() }; var categoryModel = await this.context.Categories.FindAsync(this.Food.CategoryId); if (categoryModel != null) { foodApiModel.CategoryId = categoryModel.Id; foodApiModel.CategoryName = categoryModel.Name; } else { foodApiModel.CategoryName = foodApiModel.CategoryName ?? "Meals"; } if (this.Food == null && this.Food.Pictures.Any()) { foodApiModel.PictureUrl = this.Food.Pictures.FirstOrDefault().FileName; } else { foodApiModel.PictureUrl = "defaultFood.jpg"; } return(foodApiModel); }
public void UpdateFood(int id, Domain.Food food) { _foodRepository.Update(id, food); }