public async Task <JsonResult> PromoListAll() { var user = await _userRepository.GetUser(User.Identity.Name); var promos = new List <ResPromoList>(); var allPromos = await _promoRepository.ListAll(); foreach (var promo in allPromos) { if (promo.Status == "Submitted for publishing") { var organisation = await _organisationRepository.Get(promo.OrganisationId.ToString()); var statusText = promo.Status == null ? "Draft" : promo.Status; promos.Add(new ResPromoList { Id = promo.Id, Category = promo.Category, Title = promo.Title, From = promo.From, To = promo.To, OrganisationName = organisation.Name, MaxNumberOfVoucher = promo.MaxNumberOfVoucher, StatusText = statusText }); } } return(Json(promos, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> Index() { var response = new ResponseHome(); var promos = new List <ResPromoList>(); var allPromos = await _promoRepository.ListAll(); foreach (var promo in allPromos) { if (promo.Status == "Published") { var organisation = await _organisationRepository.Get(promo.OrganisationId.ToString()); var statusText = promo.Status == null ? "Draft" : promo.Status; promos.Add(new ResPromoList { Id = promo.Id, Category = promo.Category, Title = promo.Title, Price = promo.Price, From = promo.From, To = promo.To, OrganisationName = organisation.Name, MaxNumberOfVoucher = promo.MaxNumberOfVoucher, StatusText = statusText, ShortDescription = promo.ShortDescription, OriginalPrice = promo.OriginalPrice, ImageText = promo.ImageText, Images = promo.Images }); } } if (promos.Any()) { response.Promos = promos; } return(View(response)); }