コード例 #1
0
        public async Task <long> Save(StationAccount entity)
        {
            _context.Entry(entity).State = entity.Id > 0 ? EntityState.Modified : EntityState.Added;
            await _context.SaveChangesAsync();

            return(entity.Id);
        }
コード例 #2
0
        public ActionResult Apply(long?stationId)
        {
            if (stationId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            StationAccount stationAccount = db.StationAccounts.Find(stationId.Value);

            if (stationAccount == null)
            {
                return(HttpNotFound("Station not found."));
            }

            PaymentRequestApplicationViewModel model = new PaymentRequestApplicationViewModel()
            {
                StationAccountId  = stationId.Value,
                Station           = stationAccount,
                BankAccountName   = stationAccount.BankAccountName,
                BankBranch        = stationAccount.BankBranch,
                BankAccountNumber = stationAccount.BankAccountNumber
            };

            return(View(model));
        }
コード例 #3
0
        // GET: Deposites/Cashout/5
        public ActionResult Cashout(long?accountId)
        {
            if (accountId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            StationAccount account = db.StationAccounts.Find(accountId);

            if (account == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (account.Deposite < 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            DepositeHistory depositeHistory = new DepositeHistory()
            {
                StationAccountId = accountId.Value,
                Amount           = account.Deposite
            };

            return(View(depositeHistory));
        }
コード例 #4
0
        public ActionResult Cashout([Bind(Include = "StationAccountId,Amount,ChangeType,Description,Timestamp")] DepositeHistory depositeHistory)
        {
            DateTime time = depositeHistory.Timestamp;

            if (ModelState.IsValid)
            {
                StationAccount account = db.StationAccounts.Find(depositeHistory.StationAccountId);

                if (account.Deposite < 0 || account.Deposite < depositeHistory.Amount || depositeHistory.Amount < 0)
                {
                    return(View("The deposite is not enough to cashout."));
                }

                account.Deposite          -= depositeHistory.Amount;
                depositeHistory.Amount     = depositeHistory.Amount * -1;
                depositeHistory.Timestamp  = time;
                depositeHistory.ChangeType = DepositeChangeType.Cashout;
                db.DepositeHistories.Add(depositeHistory);

                db.Entry(account).State = EntityState.Modified;

                db.SaveChanges();

                return(RedirectToAction("Index", new { accountId = depositeHistory.StationAccountId }));
            }

            return(View(depositeHistory));
        }
コード例 #5
0
        public ActionResult DeleteConfirmed(long id)
        {
            StationAccount stationAccount = db.StationAccounts.Find(id);

            //db.StationAccounts.Remove(stationAccount);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #6
0
        public async Task <long> Delete(long id)
        {
            StationAccount stationAccount = await GetById(id);

            _context.StationAccounts.Remove(stationAccount);
            await _context.SaveChangesAsync();

            return(id);
        }
コード例 #7
0
 public ActionResult Edit([Bind(Include = "StationAccountId,StationName,BankAccountName,BankAccountNumber,BankBranch")] StationAccount stationAccount)
 {
     if (ModelState.IsValid)
     {
         db.Entry(stationAccount).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(stationAccount));
 }
コード例 #8
0
        public ActionResult Create([Bind(Include = "StationAccountId,StationName,BankAccountName,BankAccountNumber,BankBranch")] StationAccount stationAccount)
        {
            if (ModelState.IsValid)
            {
                db.StationAccounts.Add(stationAccount);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(stationAccount));
        }
コード例 #9
0
        // GET: StationAccounts/Edit/5
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StationAccount stationAccount = db.StationAccounts.Find(id);

            if (stationAccount == null)
            {
                return(HttpNotFound());
            }
            return(View(stationAccount));
        }
コード例 #10
0
        public ActionResult BusinessApprove([Bind(Include = "StationAccountId, PaymentRequestId, BusinessManagerComments, IsApprove")] PaymentRequestBusinessManagerApproveViewModel businessApprove)
        {
            if (ModelState.IsValid)
            {
                PaymentRequest request = db.PaymentRequests.Find(businessApprove.PaymentRequestId);

                DateTime now = DateTime.Now;

                if (request.State != PaymentRequestState.FinanceManagerApproved)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.ExpectationFailed, "请款单不是FinanceManagerApproved状态."));
                }

                request.BusinessManagerComments = businessApprove.BusinessManagerComments;

                if (businessApprove.IsApprove == "Yes")
                {
                    request.State = PaymentRequestState.BusinessManagerApproved;

                    // Add Deposite logs
                    StationAccount account = db.StationAccounts.Find(businessApprove.StationAccountId);
                    account.Deposite += Convert.ToDouble(request.Amount);

                    var depositeHistory = new DepositeHistory()
                    {
                        StationAccountId = businessApprove.StationAccountId
                    };

                    depositeHistory.Timestamp  = now;
                    depositeHistory.ChangeType = DepositeChangeType.Recharge;
                    depositeHistory.Amount     = Convert.ToDouble(request.Amount);
                    db.DepositeHistories.Add(depositeHistory);

                    db.Entry(account).State = EntityState.Modified;
                }
                else
                {
                    request.State = PaymentRequestState.BusinessManagerRejected;
                }

                request.BusinessManagerCommentsTimestamp = now;
                request.BusinessManagerId = System.Web.HttpContext.Current.User.Identity.GetUserId();
                db.Entry(request).State   = EntityState.Modified;

                db.SaveChanges();
            }

            return(RedirectToAction("Index", new { accountId = businessApprove.StationAccountId }));
        }
コード例 #11
0
        public ActionResult PayConfirmed([Bind(Include = "SubscriptionId, Notes, Timestamp")] Subscription s)
        {
            if (ModelState.IsValid)
            {
                DateTime time = s.Timestamp;

                Subscription   subscription = db.Subscriptions.Find(s.SubscriptionId);
                long           accountId    = subscription.StationAccountId;
                StationAccount station      = db.StationAccounts.Find(accountId);


                subscription.State           = SubscriptionState.Paid;
                subscription.Timestamp       = time;
                db.Entry(subscription).State = EntityState.Modified;


                station.Deposite       -= subscription.UnitPrice * subscription.StartQuantity;
                db.Entry(station).State = EntityState.Modified;

                var subscriptionHistory = new SubscriptionHistory()
                {
                    UnitPrice      = subscription.UnitPrice,
                    State          = SubscriptionState.Paid,
                    Quantity       = subscription.StartQuantity,
                    Notes          = subscription.Notes,
                    SubscriptionId = subscription.SubscriptionId,
                    Timestamp      = time
                };

                db.SubscriptionHistories.Add(subscriptionHistory);

                var depositeHistory = new DepositeHistory()
                {
                    Amount           = subscription.UnitPrice * subscription.StartQuantity * -1,
                    ChangeType       = DepositeChangeType.Pay,
                    StationAccountId = accountId,
                    Description      = string.Format("Pay for Subscription: {0}.", subscription.SubscriptionId),
                    Timestamp        = time
                };

                db.DepositeHistories.Add(depositeHistory);

                db.SaveChanges();
                return(RedirectToAction("Index", new { accountId = accountId }));
            }

            return(View("The state is not valid."));
        }
コード例 #12
0
        public ActionResult Recharge([Bind(Include = "StationAccountId,Amount,Description,Timestamp")] DepositeHistory depositeHistory)
        {
            DateTime time = depositeHistory.Timestamp;

            if (ModelState.IsValid)
            {
                StationAccount account = db.StationAccounts.Find(depositeHistory.StationAccountId);
                account.Deposite          += depositeHistory.Amount;
                depositeHistory.Timestamp  = time;
                depositeHistory.ChangeType = DepositeChangeType.Recharge;
                db.DepositeHistories.Add(depositeHistory);

                db.Entry(account).State = EntityState.Modified;

                db.SaveChanges();

                return(RedirectToAction("Index", new { accountId = depositeHistory.StationAccountId }));
            }

            return(View(depositeHistory));
        }
コード例 #13
0
        public JsonResult DetailsJson(long id)
        {
            StationAccount stationAccount = db.StationAccounts.Find(id);

            if (stationAccount == null)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;

                return(Json("Station Not Found",
                            JsonRequestBehavior.AllowGet));
            }

            return(Json(
                       new
            {
                StationAccountId = stationAccount.StationAccountId,
                Name = stationAccount.StationName,
                BankAccountName = stationAccount.BankAccountName,
                BankAccountNumber = stationAccount.BankAccountNumber,
                Deposite = stationAccount.Deposite
            },
                       JsonRequestBehavior.AllowGet));
        }
コード例 #14
0
        private StationStatisticsViewModel GetStationStatistics(DateTime startDate, DateTime endDate, StationAccount account)
        {
            DateTime endRange = endDate.AddDays(1);

            double balanceAmount = (from dh in context.DepositeHistories
                                    where dh.StationAccountId == account.StationAccountId &&
                                    dh.Timestamp < endRange &&
                                    dh.Timestamp >= startDate
                                    select(double?) dh.Amount).Sum() ?? 0.0;

            double loan = (from dh in context.DepositeHistories
                           where dh.StationAccountId == account.StationAccountId &&
                           dh.Timestamp < endRange
                           select(double?) dh.Amount).Sum() ?? 0.0;

            loan = loan < 0 ? -1 * loan : 0;

            double quantity = (from s in context.Subscriptions
                               join
                               sh in context.SubscriptionHistories
                               on s.SubscriptionId equals sh.SubscriptionId
                               where s.StationAccountId == account.StationAccountId &&
                               sh.Timestamp >= startDate &&
                               sh.Timestamp < endRange &&
                               (sh.State == SubscriptionState.Paid)
                               select(double?) sh.Quantity).Sum() ?? 0.0;
            double refundQuantity = (from s in context.Subscriptions
                                     join
                                     sh in context.SubscriptionHistories
                                     on s.SubscriptionId equals sh.SubscriptionId
                                     where s.StationAccountId == account.StationAccountId &&
                                     sh.Timestamp >= startDate &&
                                     sh.Timestamp < endRange &&
                                     (sh.State == SubscriptionState.Refunded)
                                     select(double?) sh.Quantity).Sum() ?? 0.0;

            quantity = quantity - refundQuantity;


            var allQuantities = (from s in context.Subscriptions
                                 join
                                 sh in context.SubscriptionHistories
                                 on s.SubscriptionId equals sh.SubscriptionId
                                 where s.StationAccountId == account.StationAccountId &&
                                 sh.Timestamp < endRange &&
                                 (sh.State == SubscriptionState.Paid)
                                 //&& (s.State == SubscriptionState.Paid || s.State == SubscriptionState.PartialDelivered)
                                 select(double?) sh.Quantity).Sum() ?? 0.0;

            var deliveredQuantities = (from s in context.Subscriptions
                                       join
                                       sh in context.SubscriptionHistories
                                       on s.SubscriptionId equals sh.SubscriptionId
                                       where s.StationAccountId == account.StationAccountId &&
                                       sh.Timestamp < endRange &&
                                       (sh.State == SubscriptionState.PartialDelivered || sh.State == SubscriptionState.Delivered || sh.State == SubscriptionState.Refunded) &&
                                       (s.State == SubscriptionState.Paid || s.State == SubscriptionState.PartialDelivered || s.State == SubscriptionState.Refunded || s.State == SubscriptionState.Closed || s.State == SubscriptionState.Delivered)
                                       select(double?) sh.Quantity).Sum() ?? 0.0;

            double incompleteQuantity = allQuantities - deliveredQuantities;

            double payment = -1 * ((from dh in context.DepositeHistories
                                    where dh.StationAccountId == account.StationAccountId &&
                                    dh.Timestamp < endRange &&
                                    dh.Timestamp >= startDate &&
                                    (dh.ChangeType == DepositeChangeType.Pay || dh.ChangeType == DepositeChangeType.Refund)
                                    select(double?) dh.Amount).Sum() ?? 0.0);

            double amount = (from s in context.Subscriptions
                             join
                             sh in context.SubscriptionHistories
                             on s.SubscriptionId equals sh.SubscriptionId
                             where s.StationAccountId == account.StationAccountId &&
                             sh.Timestamp < endRange &&
                             sh.Timestamp >= startDate && sh.State == SubscriptionState.Paid
                             select(double?)(sh.Quantity * sh.UnitPrice)).Sum() ?? 0.0;

            double refundAmount = (from s in context.Subscriptions
                                   join
                                   sh in context.SubscriptionHistories
                                   on s.SubscriptionId equals sh.SubscriptionId
                                   where s.StationAccountId == account.StationAccountId &&
                                   sh.Timestamp < endRange &&
                                   sh.Timestamp >= startDate && sh.State == SubscriptionState.Refunded
                                   select(double?)(sh.Quantity * sh.UnitPrice)).Sum() ?? 0.0;

            amount = amount - refundAmount;

            return(new StationStatisticsViewModel()
            {
                StationAccountId = account.StationAccountId,
                StationAccountName = account.StationName,
                StartDate = startDate,
                EndDate = endDate,
                TotalIncompleteQuantity = incompleteQuantity,
                TotalIncreasedBalance = balanceAmount,
                TotalIncreasedLoan = loan,
                TotalIncreasedSubscriptionAmount = amount,
                TotalPaidAmount = payment,
                TotalQuantity = quantity
            });
        }