/// <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; } }
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; } }
/// <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(); }
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; } }
public IEnumerable<Transaction> GetTransactionHistory(Account userAccount) { using (ReBusContainer repository = new ReBusContainer()) { repository.AttachTo("Accounts", userAccount); repository.Refresh(RefreshMode.StoreWins, userAccount); return userAccount.Transactions; } }
/// <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(); } }
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; }
/// <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; }
/// <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); }
/// <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(); }
/// <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); }
/// <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(); } }
/// <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(); }
/// <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(); } }
/// <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(); }
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; } } }
/// <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(); }
/// <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); }