public int Create(Customer t) { int result = 0; try { //Initiate the instance of DBContext using BillingContext context = new BillingContext(); //check specific record for same Customer id is exist or not var cust = context.Customers.FirstOrDefault(c => c.CustomerId == t.CustomerId); if (cust == null) { //adding Customer object to context context.Add(t); //save changes return(result = context.SaveChanges()); } else { return(Update(t)); } } catch (Exception ex) { Exc.ErMessage(ex); return(result = 0); } }
private void ProcessCheckout() { if (CurrentCustomer == null) { CurrentCustomer = new Customer { Id = User.FindFirst(ClaimTypes.NameIdentifier)?.Value, CreditCard = Checkout.CreditCardDetails, Invoices = new List <Invoice>() { CreateInvoice() } }; BillingContext.Add(CurrentCustomer); } else { if (Checkout.SaveNewCreditCardDetails) { CurrentCustomer.CreditCard = Checkout.CreditCardDetails; } CurrentCustomer.Invoices.Add(CreateInvoice()); } CurrentItem.Status = ItemStatus.Sold; }
protected RappelzService(ArcadiaContext arcadiaContext, AuthContext authContext, BillingContext billingContext, TelecasterContext telecasterContext) { _arcadiaContext = arcadiaContext; _authContext = authContext; _billingContext = billingContext; _telecasterContext = telecasterContext; }
public bool Create(User user) { BillingContext bc = new BillingContext(new MSSQLBillingContext()); bool state = false; string query = $"INSERT INTO dbo.User INSERT INTO (email, password,billingID) VALUES (@email,@password,@billingID)"; try { if (OpenConnection()) { using (SqlCommand cmd = new SqlCommand(query, Connection)) { try { cmd.Parameters.AddWithValue("@email", user.Email); cmd.Parameters.AddWithValue("@password", user.Password); cmd.Parameters.AddWithValue("@billingID", bc.Create(user.Billing)); cmd.ExecuteNonQuery(); state = true; } catch (SqlException e) { throw e; } } } } catch (Exception e) { throw e; } return(state); }
public ClientViewModelValidator(BillingContext ctx) { RuleFor(c => c.Name) .NotEmpty() .MinimumLength(5) .MaximumLength(100) .MustAsync(async(value, x) => { return(!(await ctx.Clients.AnyAsync(c => c.Name == value))); }) .WithMessage("Name must be unique"); RuleFor(c => c.ContactName) .MaximumLength(50); When(c => !string.IsNullOrEmpty(c.Phone) || !string.IsNullOrEmpty(c.ContactName), () => { RuleFor(c => c.Phone) .NotEmpty() .WithMessage("Phone cannot be empty if contact is specified"); RuleFor(c => c.ContactName) .NotEmpty() .WithMessage("Contact name cannot be empty if phone is specified"); }); }
internal void Perform( IPerformableAction action, bool transactional = true) { if (transactional) { using (IBillingContext context = BillingContext.Create()) { using (var transaction = TransactionUtils.CreateTransaction()) { action.DbContext = context; action.Perform(); transaction.Complete(); } } } else { using (IBillingContext context = BillingContext.Create()) { action.DbContext = context; action.Perform(); } } }
internal TResult Perform <TResult>( IPerformableAction <TResult> action, bool transactional = true) { if (transactional) { using (IBillingContext context = BillingContext.Create()) { using (var transaction = TransactionUtils.CreateTransaction()) { action.DbContext = context; TResult result = action.Perform(); transaction.Complete(); return(result); } } } else { using (IBillingContext context = BillingContext.Create()) { action.DbContext = context; return(action.Perform()); } } }
// GET api/values public void Get(int id) { var address = new Address() { AddressId = 2, PostCode = "ST1 5HX", StreetName = "CenturyStreet" }; var order = new Order() { OrderId = 2, ItemName = "Laptop" }; var orders = new List <Order>(); var deliveraddress = new DeliveryAddress() { DevliverAddressID = 2, DeliveryAddressPostCode = "MK80BA", NickName = "MK- Addresss" }; address.DeliverAddress = deliveraddress; orders.Add(order); var customer = new Customer() { Name = "Danny", CustomerId = 2, CustomerAddress = address, orders = orders }; using (var context = new BillingContext()) { context.Database.Log = Console.WriteLine; context.Customers.Add(customer); context.SaveChanges(); } }
public async Task HasAccessAsync_Should_Return_Expected_ResultFalseforReportNotAllocated() { // Arrange using var deps = Initialize(); var service = new BillingService(deps.Db); var dbUser = User.Create("Test User", "*****@*****.**"); //Scenario where create 2 reports but only 2019 is allocated to user and 2020 is not allocated. var devReport2019 = Report.Create( taxYear: 2019, tradeCount: 4500, incomingTxCount: 5, outgoingTxCount: 1000, netRealizedGains: 632.60m); var devReport2020 = Report.Create( taxYear: 2020, tradeCount: 4500, incomingTxCount: 5, outgoingTxCount: 1000, netRealizedGains: 632.60m); dbUser.Reports.Add(devReport2019); deps.Db.Users.Add(dbUser); deps.Db.SaveChanges(); // Act BillingContext billingContext = new BillingContext(dbUser, devReport2020); var access = await service.HasAccessAsync(billingContext, default); // Assert access.Should().BeFalse(); }
public BillBook(BillingContext context, IRepository <Domain.TaxRate> taxRateList, IRepository <Domain.Discount> discountList, ILogger <BillingContext> logger) { this.context = context; this.taxRateList = taxRateList; this.discountList = discountList; this.logger = logger; }
public List <ReceiptHeader> Search(string t) { try { using BillingContext context = new BillingContext(); return(context.ReceiptHeaders.Where(c => c.Date.Contains(t) || c.Time.Contains(t) || c.Employee.Contains(t) || c.CheckNo.Contains(t) || c.ReceiptNo.ToString() == t || c.TotalDiscount.ToString() == t || c.SubTotal.ToString() == t || c.NetTotal.ToString() == t || c.PaidAmount.ToString() == t || c.DueAmount.ToString() == t || c.Status.ToString() == t || c.IsQuotation.ToString() == t || c.IsPaid.ToString() == t).ToList()); } catch (Exception ex) { Exc.ErMessage(ex); return(null); } }
public int Create(ReceiptBody t) { int result = 0; try { //Initiate the instance of DBContext using BillingContext context = new BillingContext(); //check specific record for same ReceiptNo is exist or not var receipt = context.ReceiptBodies.FirstOrDefault(c => c.ReceiptNo == t.ReceiptNo); if (receipt == null) { //adding receiptbody object to context context.Add(t); //save changes return(result = context.SaveChanges()); } else { context.Update(t); return(result = context.SaveChanges()); } } catch (Exception ex) { Exc.ErMessage(ex); return(result = 0); } }
public BillUnitOfWork(BillingContext billingContext, IBillRepository billRepository, IReadingRepository readingRepository) : base(billingContext) { BillRepository = billRepository; ReadingRepository = readingRepository; }
protected override void ClientProcessing(ecoMessage msg) { try { BillingContext c = (BillingContext)msg._c; ulong arg_12_0 = msg._header; byte[] arg_1E_0 = (byte[])msg._attached; new List <byte[]>(); BufferState bufferState = new BufferState(); bufferState._buffer = (byte[])msg._attached; int num = 0; List <byte[]> list = this._receiver.ReceivedBuffer(bufferState, bufferState._buffer.Length, ref num); if (list != null) { foreach (byte[] current in list) { msg._from.AsyncSend(c, current); } } } catch (Exception ex) { Common.WriteLine(ex.Message, new string[0]); } }
private int GetFactorId(ScoringFactorEnum factorName) { using (var context = new BillingContext()) { var factor = context.Set <ScoringFactor>().AsNoTracking().FirstOrDefault(f => f.Code == factorName.ToString()); return(factor?.Id ?? 0); } }
public HomeController(ILogger <HomeController> logger, BillingContext context, IMapper mapper) { _logger = logger; _context = context; _mapper = mapper; }
public TimeBillsController(ILogger <TimeBillsController> logger, BillingContext ctx, IMapper mapper) { _logger = logger; _ctx = ctx; _mapper = mapper; }
static public void InitDatabaseReports() { using (BillingContext context = new BillingContext()) { context.Database.Delete(); context.Database.Create(); } Billing.Seed.Program.Run(); }
// GET api/values/5 public List <Customer> Get() { var result = new List <Customer>(); using (var context = new BillingContext()) { result = context.Customers.Include("CustomerAddress.DeliverAddress").Include("orders").ToList(); } return(result); }
public async Task ShouldWorkAtLeast() { NpgsqlConnection.GlobalTypeMapper.MapEnum <CallType>("call_type_enum"); using (var db = new BillingContext()) { await db.BulkCopyAsync(new[] { new Call { CalledNumber = "bc" } }); } }
private void frmAgregarClientes_Load(object sender, EventArgs e) { tipoDocumentoCombobox.DisplayMember = "Tipo"; tipoDocumentoCombobox.ValueMember = "Id"; using (var db = new BillingContext()) { tipoDocumentoCombobox.DataSource = db.TipoDocumentos.ToList(); } }
/// <inheritdoc/> public Task <bool> HasAccessAsync(BillingContext context, CancellationToken cancellationToken) { bool hasAccess = false; if (context != null && context.Report != null) { hasAccess = context.User.Reports.ToList().Exists(x => x.Id == context.Report.Id); } return(Task.FromResult(hasAccess)); }
private void Add <T>(T entity, BillingContext context) where T : BaseEntity { if (entity.Id > 0) { context.Entry(entity).State = EntityState.Modified; } else { context.Entry(entity).State = EntityState.Added; } context.SaveChanges(); }
public List <ReceiptBody> View() { try { using BillingContext context = new BillingContext(); return(context.ReceiptBodies.ToList()); } catch (Exception ex) { Exc.ErMessage(ex); return(null); } }
public void WhenSkuNotFound_NoErrorThrown() { using (var context = new BillingContext(options)) { var service = GetService(context); var skus = new[] { "rickandmorty" }; var results = service.CalculateCost(skus); Assert.Equal(0, results.Count()); } }
public void GivenHarryPotterDiscounts_WhenIPurchaseNothing_ThenEmptyListIsReturned() { using (var context = new BillingContext(options)) { var service = GetService(context); var skus = new string[] {}; var results = service.CalculateCost(skus); Assert.Empty(results); } }
public List <Employee> View() { try { using BillingContext context = new BillingContext(); return(context.Employees.ToList()); } catch (Exception ex) { Exc.ErMessage(ex); return(null); } }
public List <Customer> View() { try { using BillingContext context = new BillingContext(); return(context.Customers.ToList()); } catch (Exception ex) { Exc.ErMessage(ex); return(null); } }
/// <inheritdoc/> public Task <int> CalculatePriceAsync(BillingContext context, CancellationToken cancellationToken) { //take current usage on base of user's existing Reports int tradeCount = context.User.Reports.ToList().Sum(x => x.TradeCount); //add current report trade count to get new billing criteria matching threshold range tradeCount += context.Report.TradeCount; //get best billing tier on base of trade count BillingTier billingTier = _db.BillingTiers.Where(x => x.Threshold > tradeCount). OrderBy(x1 => x1.Threshold). FirstOrDefault(); return(Task.FromResult(billingTier.FullAmountInCents)); }
public int Update(ReceiptBody t) { int result = 0; try { using BillingContext context = new BillingContext(); context.Update(t); return(result = context.SaveChanges()); } catch (Exception ex) { Exc.ErMessage(ex); return(result); } }