示例#1
0
        /// <summary>
        /// Buy a new ticket.
        /// </summary>
        /// <param name="account">The account for which to buy the ticket</param>
        /// <param name="bus">The bus for which to buy the ticket</param>
        /// <returns></returns>
        public Ticket BuyTicket(Account account, Bus bus)
        {
            using (ReBusContainer db = new ReBusContainer())
            {
                account = db.Accounts.Single(a => a.GUID == account.GUID);
                bus = db.Buses.Include("Line").Single(b => b.GUID == bus.GUID);
                var cost = db.TicketCost.Single().Cost;
                if (cost > account.Credit)
                {
                    throw new InsufficientCreditException();
                }

                var ticket = new Ticket {Account = account, Bus = bus, Created = DateTime.Now};
                var transaction = new Transaction
                                        {
                                            Account = account,
                                            Amount = cost,
                                            Type = (int) TransactionType.Ticket,
                                            Created = DateTime.Now
                                        };
                account.Credit -= cost;

                db.Tickets.AddObject(ticket);
                db.Transactions.AddObject(transaction);
                db.SaveChanges();

                return ticket;
            }
        }
示例#2
0
        public Account Register(string userName, string password, string firstName, string lastName)
        {
            if (String.IsNullOrEmpty(userName) ||
                String.IsNullOrEmpty(password) ||
                String.IsNullOrEmpty(firstName) ||
                String.IsNullOrEmpty(lastName))
            {
                throw new NotAllFieldsFilledException();
            }

            if (!UsernameIsUnique(userName))
            {
                throw new UserAlreadyExistsException();
            }

            using (ReBusContainer repository = new ReBusContainer())
            {
                Account userAccount = new Account();

                userAccount.Username = userName;
                userAccount.PasswordHash = password;
                userAccount.FirstName = firstName;
                userAccount.LastName = lastName;
                userAccount.Credit = 0;

                repository.Accounts.AddObject(userAccount);
                repository.SaveChanges();

                return userAccount;
            }
        }
示例#3
0
 /// <summary>
 /// Get latest tickets.
 /// </summary>
 /// <param name="account">The account for which to get the tickets</param>
 /// <param name="limit">The max number of thickets to fetch</param>
 /// <returns></returns>
 public IEnumerable<TicketWebServiceModel> GetHistoryWithLimit(AccountWebServiceModel account, int limit)
 {
     var dmAccount = new Account() { GUID = account.GUID };
     return ticketService.GetHistory(dmAccount, limit)
         .Select(t => TicketWebServiceModel.FromDataModel(t, account))
         .ToList();
 }
示例#4
0
 public Account AddFunds(Account account, decimal amount)
 {
     using (var db = new ReBusContainer())
     {
         account = db.Accounts.Single(a => a.GUID == account.GUID);
         account.Credit += amount;
         return account;
     }
 }
示例#5
0
        public IEnumerable<Transaction> GetTransactionHistory(Account userAccount)
        {
            using (ReBusContainer repository = new ReBusContainer())
            {
                repository.AttachTo("Accounts", userAccount);
                repository.Refresh(RefreshMode.StoreWins, userAccount);

                return userAccount.Transactions;
            }
        }
示例#6
0
        /// <summary>
        /// Get the currently active ticket of an account.
        /// </summary>
        /// <param name="account">The account for which to get the active ticket</param>
        /// <returns></returns>
        public Ticket GetActiveTicket(Account account)
        {
            using (var db = new ReBusContainer())
            {
                DateTime validity = DateTime.Now - new TimeSpan(0, 0, 45);
                return db.Tickets.Include("Account").Include("Bus").Include("Bus.Line")
                    .Where(t => t.AccountGUID == account.GUID)
                    .Where(t => t.Created >= validity)
                    .OrderByDescending(t => t.Created)
                    .FirstOrDefault();

            }
        }
示例#7
0
        internal static AccountWebServiceModel FromModelObject(Account account)
        {
            if (account == null)
                return null;

            return new AccountWebServiceModel()
                   {
                        GUID = account.GUID,
                        FirstName = account.FirstName,
                        LastName = account.LastName,
                        UserName = account.Username,
                        Credit = account.Credit
                   };
        }
        /// <summary>
        /// Buy a new subscription for all the lines
        /// </summary>
        /// <param name="account">The account for which to buy the subscription</param>
        /// <param name="startDate">The start date for the new subscription</param>
        /// <returns></returns>
        public SubscriptionWebServiceModel BuySubscriptionForAllLinesWithStartDate(AccountWebServiceModel account, DateTime startDate)
        {
            var dmAccount = new Account { GUID = account.GUID };
            SubscriptionWebServiceModel subscription = null;

            try
            {
                subscription = SubscriptionWebServiceModel.FromDataModel(subscriptionService.BuySubscription(dmAccount, startDate));
            }
            catch (Exception)
            {
            }

            return subscription;
        }
        /// <summary>
        /// Buy a new subscription
        /// </summary>
        /// <param name="account">The account for which to buy the subscription</param>
        /// <param name="lines">The lines on which the subscription applies to</param>
        /// <returns></returns>
        public SubscriptionWebServiceModel BuySubscription(AccountWebServiceModel account, IEnumerable<LineWebServiceModel> lines)
        {
            var dmAccount = new Account { GUID = account.GUID };
            var dmLines = lines.Select(l => new Line { GUID = l.GUID });
            SubscriptionWebServiceModel subscription = null;

            try
            {
                subscription = SubscriptionWebServiceModel.FromDataModel(subscriptionService.BuySubscription(dmAccount, dmLines));
            }
            catch (Exception)
            {
            }

            return subscription;
        }
示例#10
0
        /// <summary>
        /// Buy a new ticket.
        /// </summary>
        /// <param name="account">The account for which to buy the ticket</param>
        /// <param name="bus">The bus for which to buy the ticket</param>
        /// <returns></returns>
        public TicketWebServiceModel BuyTicket(AccountWebServiceModel account, BusWebServiceModel bus)
        {
            var dmAccount = new Account() {GUID = account.GUID};
            var dmBus = new Bus() {GUID = bus.GUID};

            TicketWebServiceModel ticket = null;

            try
            {
                ticket = TicketWebServiceModel.FromDataModel(ticketService.BuyTicket(dmAccount, dmBus), account);
            }
            catch (Exception)
            {
            }

            return ticket;
        }
示例#11
0
 /// <summary>
 /// Get latest tickets.
 /// </summary>
 /// <param name="account">The account for which to get the tickets</param>
 /// <param name="limit">The max number of thickets to fetch</param>
 /// <returns></returns>
 public IEnumerable<Ticket> GetHistory(Account account, int limit)
 {
     return GetHistory(account, DateTime.MaxValue, limit);
 }
示例#12
0
 /// <summary>
 /// Get the tickets that have been added after a given date (used to refresh the list with new values).
 /// </summary>
 /// <param name="account">The account for which to get the tickets</param>
 /// <param name="after">The date of the last ticket the client has</param>
 /// <returns></returns>
 public IEnumerable<TicketWebServiceModel> GetNewTickets(AccountWebServiceModel account, DateTime after)
 {
     var dmAccount = new Account() { GUID = account.GUID };
     return ticketService.GetNewTickets(dmAccount, after)
         .Select(t => TicketWebServiceModel.FromDataModel(t, account))
         .ToList();
 }
示例#13
0
 /// <summary>
 /// Get all the tickets associated to an account.
 /// </summary>
 /// <param name="account">The account for which to get the tickets</param>
 /// <returns></returns>
 public IEnumerable<Ticket> GetHistory(Account account)
 {
     return GetHistory(account, Int32.MaxValue);
 }
示例#14
0
 /// <summary>
 /// Get the tickets that have been added after a given date (used to refresh the list with new values).
 /// </summary>
 /// <param name="account">The account for which to get the tickets</param>
 /// <param name="after">The date of the last ticket the client has</param>
 /// <returns></returns>
 public IEnumerable<Ticket> GetNewTickets(Account account, DateTime after)
 {
     using (var db = new ReBusContainer())
     {
         return db.Tickets.Include("Account").Include("Bus").Include("Bus.Line")
             .Where(t => t.AccountGUID == account.GUID)
             .Where(t => t.Created > after)
             .OrderByDescending(t => t.Created).ToList();
     }
 }
示例#15
0
 /// <summary>
 /// Get all the subscriptions associated to an account.
 /// </summary>
 /// <param name="account">The account for which to get the subscriptions</param>
 /// <returns></returns>
 public IEnumerable<SubscriptionWebServiceModel> GetHistory(AccountWebServiceModel account)
 {
     var dmAccount = new Account { GUID = account.GUID };
     return subscriptionService.GetHistory(dmAccount)
         .Select(s => SubscriptionWebServiceModel.FromDataModel(s, account))
         .ToList();
 }
示例#16
0
 /// <summary>
 /// Get older tickets.
 /// </summary>
 /// <param name="account">The account for which to get the tickets</param>
 /// <param name="before">The date before which to get the tickets</param>
 /// <param name="limit">The max number of thickets to fetch</param>
 /// <returns></returns>
 public IEnumerable<Ticket> GetHistory(Account account, DateTime before, int limit)
 {
     using (var db = new ReBusContainer())
     {
         return db.Tickets.Include("Account").Include("Bus").Include("Bus.Line")
             .Where(t => t.AccountGUID == account.GUID)
             .Where(t => t.Created < before)
             .OrderByDescending(t => t.Created)
             .Take(limit).ToList();
     }
 }
示例#17
0
 /// <summary>
 /// Get the subscriptions that have been added after a given date (used to refresh the list with new values).
 /// </summary>
 /// <param name="account">The account for which to get the subscriptions</param>
 /// <param name="after">The date of the last subscription the client has</param>
 /// <returns></returns>
 public IEnumerable<SubscriptionWebServiceModel> GetNewSubscriptions(AccountWebServiceModel account, DateTime after)
 {
     var dmAccount = new Account { GUID = account.GUID };
     return subscriptionService.GetNewSubscriptions(dmAccount, after)
         .Select(s => SubscriptionWebServiceModel.FromDataModel(s, account))
         .ToList();
 }
示例#18
0
        private void FixupAccount(Account previousValue)
        {
            if (previousValue != null && previousValue.Transactions.Contains(this))
            {
                previousValue.Transactions.Remove(this);
            }

            if (Account != null)
            {
                if (!Account.Transactions.Contains(this))
                {
                    Account.Transactions.Add(this);
                }
                if (AccountGUID != Account.GUID)
                {
                    AccountGUID = Account.GUID;
                }
            }
        }
示例#19
0
 /// <summary>
 /// Get older subscriptions.
 /// </summary>
 /// <param name="account">The account for which to get the subscriptions</param>
 /// <param name="before">The date before which to get the subscriptions</param>
 /// <param name="limit">The max number of subscriptions to fetch</param>
 /// <returns></returns>
 public IEnumerable<SubscriptionWebServiceModel> GetNextHistoryWithLimit(AccountWebServiceModel account, DateTime before, int limit)
 {
     var dmAccount = new Account { GUID = account.GUID };
     return subscriptionService.GetHistory(dmAccount, before, limit)
         .Select(s => SubscriptionWebServiceModel.FromDataModel(s, account))
         .ToList();
 }
示例#20
0
 /// <summary>
 /// Get the currently active ticket of an account.
 /// </summary>
 /// <param name="account">The account for which to get the active ticket</param>
 /// <returns></returns>
 public TicketWebServiceModel GetActiveTicket(AccountWebServiceModel account)
 {
     var dmAccount = new Account() {GUID = account.GUID};
     return TicketWebServiceModel.FromDataModel(ticketService.GetActiveTicket(dmAccount), account);
 }