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