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 async Task <bool> Put(FoodApiModel model) { return(await this.FoodService.UpdateFoodAsync(model)); }
public async Task <bool> Post(FoodApiModel model) { return(await this.FoodService.AddFoodAsync(model)); }