private JsonRespondBody OrderInfoMethod(JsonRequestBody json)
{
aspnetuser user = DataManager.User.GetUserByToken(json.Token);
int id_order = 0;
if (user == null)
{
return new JsonRespondBody { Error = "Invalid token", Status = "error" };
}
if (!json.Parameters.ContainsKey("Id_Order"))
{
return new JsonRespondBody { Error = "Id_Order is required", Status = "error" };
}
try
{
id_order = Convert.ToInt32(json.Parameters["Id_Order"]);
}
catch
{
return new JsonRespondBody { Error = "Invalid parameters", Status = "warning" };
}
order o = DataManager.Order.GetOrderById(id_order);
if (o == null)
{
return new JsonRespondBody { Error = "Order not found", Status = "warning" };
}
if (o.Id_Cook != user.Id && o.Id_Customer != user.Id)
{
return new JsonRespondBody { Error = "Access denied", Status = "warning" };
}
//формируем ответ
string address = string.Format("{0}://{1}", Request.Url.Scheme, Request.Url.Authority);
IEnumerable<orderproduct> op = DataManager.Order.GetOrderProducts(o.Id_Order);
List<DishSerealizerBody> dl = new List<DishSerealizerBody>();
foreach (var item in op)
{
dl.Add(new DishSerealizerBody
{
Id = item.Id_Dish,
Name = item.dish.Name,
Price = item.Price,
PriceWithIngridients = item.PriceWithIngridients,
Image = address + item.dish.ImageUrl
});
}
DataManager.User.RefreshBuffer();
OrderSerializerBody res = GetOrderInformation(o);
res.OrderList = dl;
JsonRespondBody result = new JsonRespondBody { Status = "OK", Result = res };
return result;
}