public async Task <IHttpActionResult> Get(int id) { Resto resto = await db.Restos.FirstOrDefaultAsync(v => v.Id == id); if (resto == null) { return(NotFound()); } var userName = User.Identity.GetUserName(); var user = await UserManager.FindByNameAsync(userName); if (user == null) { return(BadRequest("User Authentication failed")); } ListRestoAPIModel restoAPI = new ListRestoAPIModel { ResponseHeader = new ResponseHeaderAPIModel { SpecVersion = ConfigurationManager.AppSettings["CurrentAPIVersion"] }, Restos = new List <RestoAPIModel> { new RestoAPIModel { Address = resto.Address, Description = resto.Description, Id = resto.Id, Image = resto.Image, Name = resto.Name, PhoneNumber = resto.PhoneNumber, Menu = new MenuAPIModel { MenuId = resto.Menu.MenuId, Name = resto.Menu.Name, ItemList = new List <ItemAPIModel>() } } } }; foreach (var item in resto.Menu.ItemList) { if (item.DeletedOn == null) { ItemAPIModel newItem = new ItemAPIModel { Name = item.Name, Brand = item.Brand, UnitPrice = item.UnitPrice, Description = item.Description, HasSize = item.HasSize, ItemId = item.ItemId, CanBeHotNotCold = item.CanBeHotNotCold, CanBeSalt = item.CanBeSalt, CanHaveMeat = item.CanHaveMeat, CanHaveSauce = item.CanHaveSauce, TypeOfFood = item.TypeOfFood, AvailableSizes = new List <SizedMeal>() }; foreach (var itemsize in item.AvailableSizes) { newItem.AvailableSizes.Add(new SizedMeal { MealSize = itemsize.MealSize, Id = itemsize.Id, Price = itemsize.Price }); } restoAPI.Restos[0].Menu.ItemList.Add(newItem); } } return(Ok(restoAPI)); }
public async Task <IHttpActionResult> Get() { List <Resto> restos = await db.Restos.ToListAsync(); if (restos == null) { return(NotFound()); } ListRestoAPIModel APIRestos = new ListRestoAPIModel(); APIRestos.ResponseHeader = new ResponseHeaderAPIModel { SpecVersion = ConfigurationManager.AppSettings["CurrentAPIVersion"] }; APIRestos.Restos = new List <RestoAPIModel>(); foreach (var resto in restos) { RestoAPIModel restoAPIModel = new RestoAPIModel { Address = resto.Address, Description = resto.Description, Id = resto.Id, Image = resto.Image, Name = resto.Name, PhoneNumber = resto.PhoneNumber, }; if (resto.Menu != null) { restoAPIModel.Menu = new MenuAPIModel { MenuId = resto.Menu.MenuId, Name = resto.Menu.Name, ItemList = new List <ItemAPIModel>() }; if (resto.Menu.ItemList != null) { foreach (var item in resto.Menu.ItemList) { if (item.DeletedOn == null) { restoAPIModel.Menu.ItemList.Add(new ItemAPIModel { Name = item.Name, Brand = item.Brand, UnitPrice = item.UnitPrice, Description = item.Description, HasSize = item.HasSize, ItemId = item.ItemId, CanBeHotNotCold = item.CanBeHotNotCold, CanBeSalt = item.CanBeSalt, CanHaveMeat = item.CanHaveMeat, CanHaveSauce = item.CanHaveSauce, TypeOfFood = item.TypeOfFood }); } } } } APIRestos.Restos.Add(restoAPIModel); } return(Ok(APIRestos)); }