//[Authorize(Roles = "Company")] //[Authorize(Roles = "User")] public ActionResult Get() { var comemer = context.Commerce.ToList(); var listCommerceResult = new List <ModelCommerce>(); var objModel = new ModelCommerce(); var cont = 0; foreach (Commerce com in comemer) { objModel = new ModelCommerce(); objModel.Id = com.Id; objModel.Name = context.BusinessModels.FirstOrDefault((x => x.Id == context.BussinessCommerce.FirstOrDefault(x => x.Commerce == com.Id).Bussines)).Name; objModel.Image = context.BusinessModels.FirstOrDefault((x => x.Id == context.BussinessCommerce.FirstOrDefault(x => x.Commerce == com.Id).Bussines)).Image; objModel.Latitude = com.Latitude; objModel.Longitude = com.Longitude; objModel.Phone = com.Phone; objModel.Address = com.Address; objModel.Discounts = ListDiscountCommerce(com.Id, ref cont); //com.Discounts = ListDiscountCommerce(com.Id); listCommerceResult.Add(objModel); } return(Ok(new { results = listCommerceResult })); //return context.Commerce.ToList(); }
private List <ModelCommerce> ListOfCommerce(int idInterest) { var Discount = new List <Discounts>(); var ListIdDiscount = new List <DiscountsInterests>(); ListIdDiscount = context.DiscountsInterests.Where(x => x.InterestsId == idInterest).ToList(); var cont = 0; foreach (DiscountsInterests Cont in ListIdDiscount) { Discount.Add(context.Discounts.SingleOrDefault(x => x.Id == Cont.DiscountsID)); } var prueba = new List <int>(); foreach (Discounts y in Discount) { prueba.Add(context.CommerceDiscounts.FirstOrDefault(x => x.DiscountsID == y.Id).CommerceID); } var listofcommerce = new List <Commerce>(); foreach (int contador in prueba.Distinct()) { listofcommerce.Add(context.Commerce.FirstOrDefault(x => x.Id == contador)); } var listCommerceResult = new List <ModelCommerce>(); var objModel = new ModelCommerce(); foreach (Commerce com in listofcommerce) { objModel = new ModelCommerce(); objModel.Id = com.Id; objModel.Name = context.BusinessModels.FirstOrDefault((x => x.Id == context.BussinessCommerce.FirstOrDefault(x => x.Commerce == com.Id).Bussines)).Name; objModel.Image = context.BusinessModels.FirstOrDefault((x => x.Id == context.BussinessCommerce.FirstOrDefault(x => x.Commerce == com.Id).Bussines)).Image; objModel.Latitude = com.Latitude; objModel.Longitude = com.Longitude; objModel.Phone = com.Phone; objModel.Address = com.Address; objModel.Discounts = ListDiscountCommerce(com.Id, ref cont); //com.Discounts = ListDiscountCommerce(com.Id); listCommerceResult.Add(objModel); } if (listCommerceResult == null) { return(listCommerceResult); } return(listCommerceResult); }