public async Task <SubscribesIndexViewModel> GetSubscribesIndexViewAsync(string userId, bool allData = false) { var subscribes = await _subscribesService.FetchByUserAsync(userId); var model = new SubscribesIndexViewModel(); if (subscribes.HasItems()) { subscribes = subscribes.GetOrdered(); //User訂閱紀錄 model.Records = subscribes.MapViewModelList(_mapper); //訂閱期之內(Active)的訂閱紀錄 var activeSubscribe = subscribes.Where(item => item.Active).FirstOrDefault(); if (activeSubscribe != null) { model.Current = activeSubscribe.MapViewModel(_mapper); } } if (model.Current == null) { //目前不在訂閱期 var plan = await FindActivePlanAsync(); if (plan != null) { bool canDiscount = subscribes.HasItems(); model.Plan = plan.MapViewModel(_mapper, canDiscount); } } if (allData) { var bills = await _billsService.FetchByUserAsync(userId); if (bills.HasItems()) { bills = bills.OrderByDescending(x => x.CreatedAt); } model.Bills = bills.MapViewModelList(_mapper); var payways = (await _paysService.FetchPayWaysAsync()).GetOrdered(); model.PayWays = payways.MapViewModelList(_mapper); } return(model); }
public async Task <ActionResult> Index() { var model = await GetIndexViewAsync(); var bills = await _billsService.FetchByUserAsync(CurrentUserId); if (bills.HasItems()) { bills = bills.OrderByDescending(x => x.CreatedAt); } model.Bills = bills.MapViewModelList(_mapper); var payways = (await _paysService.FetchPayWaysAsync()).GetOrdered(); model.PayWays = payways.MapViewModelList(_mapper); return(Ok(model)); }
public async Task <ActionResult> Edit(int id) { var bill = _billsService.GetById(id); if (bill == null) { return(NotFound()); } if (bill.Payed) { return(NotFound()); //已經支付, 應該去Details } var form = new BillEditForm() { Bill = bill.MapViewModel(_mapper) }; bool canPay = !bill.Expired; if (canPay) { var bills = await _billsService.FetchByUserAsync(new User { Id = CurrentUserId }, new Plan { Id = bill.PlanId }); if (bills.HasItems()) { //查看是否已經有同方案, 已支付的帳單 var payedBill = bills.Where(x => x.Payed).FirstOrDefault(); if (payedBill != null) { canPay = false; } } } if (canPay) { var payways = (await _paysService.FetchPayWaysAsync()).GetOrdered(); form.PayWays = payways.MapViewModelList(_mapper); } return(Ok(form)); }