public bool Insert(AirtimeBilling.Core.Entities.Agent entity) { if (entity == null) { throw new ArgumentNullException("No Agent supplied"); } if (entity.Id != null) { throw new ArgumentOutOfRangeException("Agent Id is not null"); } try { using (var db = DbFactory.GetDataContext()) { var agent = new Agent(); PopulateAgentFromAgentEntity(entity, ref agent); db.Agents.InsertOnSubmit(agent); db.SubmitChanges(); entity.Inserted(agent.AgentId); return true; } } catch (Exception ex) { LoggingUtility.LogException(ex); } return false; }
public static void PopulateFromEntity(this Contract contract, AirtimeBilling.Core.Entities.Contract entity) { contract.PlanId = entity.PlanId; contract.AgentId = entity.AgentId; contract.ContractNumber = entity.ContractNumber; contract.ActivationDate = entity.ActivationDate; contract.EndDate = entity.EndDate; contract.IMEINumber = entity.IMEINumber; contract.SimCard = entity.SimCard; contract.PhoneUsedBy = entity.UsedBy; contract.PhoneNumber1 = entity.PhoneNumber1; contract.PhoneNumber2 = entity.PhoneNumber2; contract.PhoneNumber3 = entity.PhoneNumber3; contract.PhoneNumber4 = entity.PhoneNumber4; contract.Data = entity.Data; contract.MessageBank = entity.MessageBank; contract.AccountId = entity.AccountId; contract.ContractStatus = (int)entity.ContractStatus; contract.Puk = entity.Puk; contract.Pin = entity.Pin; contract.StatusChangedDate = entity.StatusChangedDate; contract.SuspensionStartDate = entity.SuspensionStartDate; contract.SuspendedUntilDate = entity.SuspendedUntilDate; contract.OrderReceivedDate = entity.OrderReceivedDate; }
public static void PopulateFromEntity(this Account acc, AirtimeBilling.Core.Entities.Account entity) { acc.AccountNumber = entity.AccountNumber; acc.AccountName = entity.AccountName; acc.ContactId = entity.ContactId; acc.ContactRole = entity.ContactRole; acc.BillingMethod = (int)entity.BillingMethod; acc.EmailBillDataFile = entity.EmailBillDataFile; acc.EmailBill = entity.EmailBill; acc.PostBill = entity.PostBill; acc.BillingAddressType = (int)entity.BillingAddressType; acc.Password = entity.Password; acc.IsInvoiceRoot = entity.IsInvoiceRoot; acc.HasRequestedInvoicing = entity.HasRequestedInvoicing; acc.IsInternational = entity.IsInternational; if (entity is SubAccount) { acc.ParentAccountId = ((SubAccount)entity).MasterAccountId; } else if (entity is MasterAccount) { acc.CompanyId = ((MasterAccount)entity).CompanyId; acc.AmountPaid = ((MasterAccount)entity).AmountPaid; acc.PreviousBill = ((MasterAccount)entity).PreviousBill; } }
public bool Insert(AirtimeBilling.Core.Entities.Note entity) { if (entity == null) throw new ArgumentNullException("No Note supplied."); if (entity.Id != null ) throw new ArgumentNullException("Note Id is not null"); try { using (var db = DbFactory.GetDataContext()) { var note = new Note(); note.PopulateFromEntity(entity); db.Notes.InsertOnSubmit(note); db.SubmitChanges(); entity.Inserted(note.NoteId); return true; } } catch (Exception ex) { LoggingUtility.LogException(ex); throw; } }
public static void PopulateFromEntity(this Note note, AirtimeBilling.Core.Entities.Note entity) { note.Type = entity.NoteType; note.Comment = entity.Comment; note.EntityId = entity.EntityId; note.NoteDate = entity.NoteDate; note.Username = entity.Username; }
public static void PopulateFromEntity(this EwayProcessedData data, AirtimeBilling.Core.Entities.EwayProcessedData entity) { data.EwayTransactionReference = entity.EwayTransactionReference; data.CardHolder = entity.CardHolder; data.Amount = entity.Amount; data.EwayInvoiceReference = entity.EwayInvoiceReference; data.InvoiceNumber = entity.InvoiceNumber; data.ResponseCode = entity.ResponseCode; data.ResponseText = entity.ResponseText; }
public void Delete(AirtimeBilling.Core.Entities.Contact entity) { using (var db = DbFactory.GetDataContext()) { var contact = db.Contacts.FirstOrDefault(c => c.ContactId == entity.Id.Value); if (contact != null) { db.Contacts.DeleteOnSubmit(contact); db.SubmitChanges(); } } }
public void Delete(AirtimeBilling.Core.Entities.Account entity) { using (var db = DbFactory.GetDataContext()) { var account = db.Accounts.FirstOrDefault(a => a.AccountId == entity.Id.Value); if (account != null) { db.Accounts.DeleteOnSubmit(account); db.SubmitChanges(); } } }
public void Delete(AirtimeBilling.Core.Entities.CustomFee entity) { using (var db = DbFactory.GetDataContext()) { var fee = db.CustomFees.SingleOrDefault(f => f.CustomFeeId == entity.Id.Value); if (fee != null) { db.CustomFees.DeleteOnSubmit(fee); db.SubmitChanges(); } } }
public void Insert(AirtimeBilling.Core.Entities.EwayProcessedData entity) { using (var db = DbFactory.GetDataContext()) { var data = new EwayProcessedData(); data.PopulateFromEntity(entity); db.EwayProcessedDatas.InsertOnSubmit(data); db.SubmitChanges(); entity.Inserted(data.EwayProcessedDataId); } }
public bool Delete(AirtimeBilling.Core.Entities.Contract entity) { if (entity == null) return false; using (var db = DbFactory.GetDataContext()) { bool? result = false; db.DeleteContract(entity.Id, ref result); {} if (result.HasValue) return result.Value; else return false; } }
public static void PopulateFromEntity(this Company company, AirtimeBilling.Core.Entities.Company entity) { company.CompanyName = entity.CompanyName; company.ABN = entity.ABN; company.ACN = entity.ACN; company.Street = entity.Address.Street; company.Street2 = entity.Address.Street2; company.Suburb = entity.Address.Suburb; company.State = entity.Address.State; company.Postcode = entity.Address.Postcode; company.PostalStreet = entity.PostalAddress.Street; company.PostalStreet2 = entity.PostalAddress.Street2; company.PostalSuburb = entity.PostalAddress.Suburb; company.PostalState = entity.PostalAddress.State; company.PostalPostcode = entity.PostalAddress.Postcode; }
public void Insert(AirtimeBilling.Core.Entities.CustomFee entity) { if (entity.Id.HasValue) { Update(entity); return; } using (var db = DbFactory.GetDataContext()) { var fee = new CustomFee(); fee.PopulateFromEntity(entity); db.CustomFees.InsertOnSubmit(fee); db.SubmitChanges(); entity.Inserted(fee.CustomFeeId); } }
public bool AddCustomFee(int contractId, AirtimeBilling.Core.Entities.CustomFee customFee) { using (var db = DbFactory.GetDataContext()) { if (db.ContractCustomFees.SingleOrDefault(f => f.ContractId == contractId && f.CustomFeeId == customFee.Id.Value) != null) return true; var contractCustomFee = new ContractCustomFee { ContractId = contractId, CustomFeeId = customFee.Id.Value }; db.ContractCustomFees.InsertOnSubmit(contractCustomFee); db.SubmitChanges(); return true; } }
public void InsertNetworkTariff(AirtimeBilling.Core.Entities.NetworkTariff entity) { if (entity == null) return; using (var db = DbFactory.GetDataContext()) { var tariff = new NetworkTariff(); PopulateNetworkTariffFromEntity(entity, ref tariff); db.NetworkTariffs.InsertOnSubmit(tariff); try { db.SubmitChanges(); entity.Inserted(tariff.NetworkTariffId); } catch (ChangeConflictException) { // Try again if there's a concurrency error db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, db.NetworkTariffs); db.SubmitChanges(); } } }
public void InsertAccount(AirtimeBilling.Core.Entities.Account account) { using (var db = DbFactory.GetDataContext()) { var acc = new Account(); acc.PopulateFromEntity(account); db.Accounts.InsertOnSubmit(acc); db.SubmitChanges(); account.Inserted(acc.AccountId); } }
public bool UpdateContract(AirtimeBilling.Core.Entities.Contract contract) { using (var db = DbFactory.GetDataContext()) { var cont = db.Contracts.Where(c => c.ContractId == contract.Id.Value).SingleOrDefault(); if (cont != null) { cont.PopulateFromEntity(contract); db.SubmitChanges(); } return true; } }
public int InsertContractPlanVariance(AirtimeBilling.Core.Entities.Contract contract, AirtimeBilling.Core.Entities.Plan newPlan, DateTime startDate, DateTime endDate, string user, decimal cost) { using (var db = DbFactory.GetDataContext()) { var variance = new ContractPlanVariance { CreatedOn = DateTime.Now, Username = user, StartDate = startDate, EndDate = endDate, Cost = cost, PlanId = newPlan.Id.Value, ContractId = contract.Id.Value }; db.ContractPlanVariances.InsertOnSubmit(variance); db.SubmitChanges(); return variance.ContractPlanVarianceId; } }
public IList<AirtimeBilling.Core.Entities.CustomFee> GetAllCustomFeesForContract(AirtimeBilling.Core.Entities.Contract contract) { IList<AirtimeBilling.Core.Entities.CustomFee> customFees = new List<AirtimeBilling.Core.Entities.CustomFee>(); using (var db = DbFactory.GetDataContext()) { var fees = from cont in db.Contracts where cont.ContractId == contract.Id.Value select cont.ContractCustomFee; foreach (var fee in fees) { var item = new AirtimeBilling.Core.Entities.CustomFee(fee.ContractCustomFeeId) { Description = fee.CustomFee.Description, Amount = fee.CustomFee.Amount, IsRecurring = fee.CustomFee.IsRecurring }; customFees.Add(item); } } // TODO return customFees; }
public IList<AirtimeBilling.Core.Entities.Contract> GetAllContractsWithCustomFee(AirtimeBilling.Core.Entities.CustomFee customFee) { using (var db = DbFactory.GetDataContext()) { IList<AirtimeBilling.Core.Entities.Contract> contracts = new List<AirtimeBilling.Core.Entities.Contract>(); return contracts; } }
private void PopulatePlanFromPlanEntity(AirtimeBilling.Core.Entities.Plan entity, ref Plan plan) { plan.Name = entity.Name; plan.Duration = entity.Duration; plan.Flagfall = entity.FlagFall; plan.FreeCallAmount = entity.FreeCallAmount; plan.PlanAmount = entity.PlanAmount; plan.NetworkId = entity.NetworkId; plan.DefaultTariffId = entity.DefaultTariffId; plan.UnitOfTime = entity.UnitOfTime; }
public bool UpdateNetworkTariff(AirtimeBilling.Core.Entities.NetworkTariff entity) { using (var db = DbFactory.GetDataContext()) { var tariff = db.NetworkTariffs.SingleOrDefault(t => t.NetworkTariffId == entity.Id.Value); if (tariff != null) { PopulateNetworkTariffFromEntity(entity, ref tariff); try { db.SubmitChanges(); } catch (ChangeConflictException) { db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, db.NetworkTariffs); db.SubmitChanges(); } // if it gets to here it must have succeeded. return true; } else { throw new UnknownEntityException(string.Format("Could not find NetworkTariff with Id={0}", entity.Id.Value)); } } }
public bool UpdateContact(AirtimeBilling.Core.Entities.Contact contact) { // Can't update new contacts! if (contact.Id == null) { throw new Exception("Cannot update new Contacts"); } using (var db = DbFactory.GetDataContext()) { Contact cont = db.Contacts.Where(c => c.ContactId == contact.Id.Value).SingleOrDefault(); if (cont != null) { cont.PopulateFromEntity(contact); db.SubmitChanges(); return true; } else { throw new Exception("Could not find this Contact in the database"); } } }
private void PopulateAgentFromAgentEntity(AirtimeBilling.Core.Entities.Agent entity, ref Agent agent) { Debug.Assert(entity != null); agent.AgentName = entity.AgentName; agent.Street = entity.Address.Street; agent.Suburb = entity.Address.Suburb; agent.State = entity.Address.State; agent.Postcode = entity.Address.Postcode; agent.Email = entity.Email; agent.CommissionPercent = (double)entity.CommissionPercent; }
public void InsertPlan(AirtimeBilling.Core.Entities.Plan plan) { using (var db = DbFactory.GetDataContext()) { Plan p = new Plan(); PopulatePlanFromPlanEntity(plan, ref p); p.IsActive = true; db.Plans.InsertOnSubmit(p); db.SubmitChanges(); plan.Inserted(p.PlanId); } }
public bool Update(AirtimeBilling.Core.Entities.Agent entity) { if (entity == null || entity.Id == null) { throw new InvalidOperationException("Could not update non-existing Agent"); } try { using (var db = DbFactory.GetDataContext()) { var agent = db.Agents.Where(a => a.AgentId == entity.Id.Value).SingleOrDefault(); if (agent != null) { PopulateAgentFromAgentEntity(entity, ref agent); db.SubmitChanges(); return true; } throw new Exception("Could not find Agent with Id=" + entity.Id.Value.ToString()); } } catch (Exception ex) { LoggingUtility.LogException(ex); } return false; }
public void InsertContact(AirtimeBilling.Core.Entities.Contact contact) { using (var db = DbFactory.GetDataContext()) { var cont = new Contact(); cont.PopulateFromEntity(contact); db.Contacts.InsertOnSubmit(cont); db.SubmitChanges(); contact.Inserted(cont.ContactId); } }
public bool UpdateAccount(AirtimeBilling.Core.Entities.Account account) { using (var db = DbFactory.GetDataContext()) { var acc = db.Accounts.Where(a => a.AccountId == account.Id.Value).SingleOrDefault(); if (acc != null) { acc.PopulateFromEntity(account); bool success = true; try { db.SubmitChanges(); } catch (Exception ex) { // TODO Log Exception LoggingUtility.LogException(ex); success = false; } return success; } else { throw new UnknownEntityException(string.Format("Could not find Account with Id={0} in the database", account.Id.Value)); } } }
public void Update(AirtimeBilling.Core.Entities.CustomFee entity) { // Can't update new contacts! if (entity.Id == null) { Insert(entity); return; } using (var db = DbFactory.GetDataContext()) { var fee = db.CustomFees.SingleOrDefault(f => f.CustomFeeId == entity.Id.Value); if (fee != null) { fee.PopulateFromEntity(entity); db.SubmitChanges(); } else { throw new Exception("Could not find this Custom Fee in the database"); } } }
private void PopulateNetworkTariffFromEntity(AirtimeBilling.Core.Entities.NetworkTariff entity, ref NetworkTariff tariff) { tariff.Code = entity.Code; tariff.IsCountedInFreeCall = entity.IsCountedInFreeCall; tariff.NetworkId = entity.NetworkId; tariff.Tariff = entity.Name; tariff.HasFlagfall = entity.HasFlagfall; }