public async Task <IActionResult> PutBillingEntry([FromRoute] Guid id, [FromBody] BillingEntry billingEntry) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != billingEntry.Id) { return(BadRequest()); } _context.Entry(billingEntry).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BillingEntryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public NewBillingEntryPage() { InitializeComponent(); Entry = new BillingEntry(); Entry.Id = Guid.NewGuid(); Entry.BillingDate = DateTime.Now; BindingContext = this; }
public static async Task <bool> DeleteBillableAsync(BillingEntry entry) { if (client.State != System.ServiceModel.CommunicationState.Opened) { await client.OpenAsync(); } bool result = await client.DeleteEntryAsync(entry.BillableId); //await client.CloseAsync(); return(result); }
public async Task <IActionResult> PostBillingEntry([FromBody] BillingEntry billingEntry) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.BillingEntries.Add(billingEntry); await _context.SaveChangesAsync(); return(CreatedAtAction("GetBillingEntry", new { id = billingEntry.Id }, billingEntry)); }
public BillingEntryDetailPage() { InitializeComponent(); var item = new BillingEntry() { Id = Guid.NewGuid() }; viewModel = new BillingEntryDetailViewModel(item); BindingContext = viewModel; }
public BillingEntryDetailViewModel(BillingEntry item = null) { Title = item?.ClientName; Entry = new BillingEntry(); Entry.ClientName = item?.ClientName; Entry.Notes = item?.Notes; if (item != null) { Entry.Id = item.Id; Entry.BillingDate = item.BillingDate; Entry.BillingTime = item.BillingTime; } }
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState) { //Value = (suspensionState.ContainsKey(nameof(Value))) ? suspensionState[nameof(Value)]?.ToString() : parameter?.ToString(); if (parameter != null) { billable = new BillingEntry(); BillingEntry b = (BillingEntry)parameter; billable.BillableId = b.BillableId; billable.BillableDate = b.BillableDate; billable.BillableTime = b.BillableTime; billable.ClientName = b.ClientName; billable.Notes = b.Notes; } await Task.CompletedTask; }
protected async void CreateBillEntry() { Billing bill = null; if (!revenue.dueDate.HasValue) { await JSRuntime.InvokeVoidAsync("alert", "Due date is required."); return; } if (BillingType.Equals("MB")) { bill = await appDBContext.Billings .Include(b => b.propertyDirectory) .Where(b => b.propertyDirectory.propertyId.Equals(revenue.propertyId) && b.propertyDirectory.tenandId.Equals(revenue.tenantId) && revenue.dueDate.Value >= b.propertyDirectory.dateFrom && revenue.dueDate.Value <= b.propertyDirectory.dateTo && b.companyId.Equals(CompanyId) && b.billType.Equals(BillingType) && b.MonthYear.Equals(revenue.dueDate.Value.ToString("yyyyMM")) ).FirstOrDefaultAsync(); } //if(bill!=null) //{ // revenue.billingDocumentId = bill.documentId; // revenue.billingId = bill.billId.ToString(); // if(bill.balance>0) // { // this.revenue.amount = bill.balance; // this.revenue.checkAmount = bill.balance; // } // StateHasChanged(); // return; //} var pd = await appDBContext.PropertyDirectory .Where(b => b.propertyId.Equals(revenue.propertyId) && b.tenandId.Equals(revenue.tenantId) && revenue.dueDate.Value >= b.dateFrom && revenue.dueDate.Value <= b.dateTo && b.companyId.Equals(CompanyId)).FirstOrDefaultAsync(); if (pd == null) { await JSRuntime.InvokeVoidAsync("alert", "Tenant is not currently renting the selected property."); return; } var billingId = bill == null ? string.Empty : bill.billId.ToString(); BillingEntry.InitParameters(revenue.propertyId, revenue.tenantId, revenue.dueDate, BillingType, billingId); await BillingEntry.InitNewBilling(); BillingEntry.OpenDialogBox(); StateHasChanged(); }
/// <summary> /// Emits the usage event to the configured MARKETPLACEAPI_URI. /// </summary> private static async Task <HttpResponseMessage> EmitUsageEvents(IConfigurationRoot config, HttpClient httpClient, DimensionConfig dimensionConfig, BillingEntry billingEntry) { var usageEvent = new UsageEventDefinition { ResourceId = billingEntry.resourceUsageId, Quantity = dimensionConfig.Quantity, Dimension = dimensionConfig.Dimension, EffectiveStartTime = DateTime.UtcNow, PlanId = billingEntry.planId }; if (CronJob.IsLocalRun(config)) { return(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(usageEvent), UnicodeEncoding.UTF8, "application/json"), StatusCode = HttpStatusCode.OK }); } return(await httpClient.PostAsJsonAsync(config["MARKETPLACEAPI_URI"], usageEvent).ConfigureAwait(continueOnCapturedContext: false)); }
public NewBillablePageViewModel() { billable = new BillingEntry(); billable.BillableId = Guid.NewGuid(); billable.BillableDate = DateTime.Now; }
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState) { if (suspensionState.Any()) { } if (mode == NavigationMode.New && Billables.Count == 0) { Billables = await DataHelper.GetBillablesAsync(); // FileHelper.GetBillablesAsync(); //Billables.Add(new Billable //{ // BillableId = Guid.NewGuid(), // ClientName = "Jimbo Jones", // BillableDate = DateTime.Now, // BillableTime = new TimeSpan(1, 45, 0), // Notes = "Loves Beanies and breaking things" //}); //Billables.Add(new Billable //{ // BillableId = Guid.NewGuid(), // ClientName = "Nelson Muntz", // BillableDate = DateTime.Now, // BillableTime = new TimeSpan(2, 30, 0), // Notes = "Little slow .. but loves a good laugh" //}); //Billables.Add(new Billable //{ // BillableId = Guid.NewGuid(), // ClientName = "Kearney Zzyzwicz", // BillableDate = DateTime.Now, // BillableTime = new TimeSpan(2, 30, 0), // Notes = "Way to old to still be in school" //}); //Billables.Add(new Billable //{ // BillableId = Guid.NewGuid(), // ClientName = "Dolph Starbeam", // BillableDate = DateTime.Now, // BillableTime = new TimeSpan(1, 10, 0), // Notes = "Hippie parents" //}); //await FileHelper.SetBillablesAsync(Billables); } if (parameter != null && mode != NavigationMode.Back) { BillingEntry billable = (BillingEntry)parameter; BillingEntry b; try { b = Billables.First(i => i.BillableId == billable.BillableId); if (await DataHelper.UpdateBillableAsync(b)) { b.BillableDate = billable.BillableDate; b.BillableTime = billable.BillableTime; b.ClientName = billable.ClientName; b.Notes = billable.Notes; RaisePropertyChanged(); } } catch { if (await DataHelper.CreateBillableAsync(billable)) { Billables.Add(billable); } } //await FileHelper.SetBillablesAsync(Billables); } SetDisplayTotal(); await Task.CompletedTask; }
public void BillableSelectionChanged(object sender, SelectionChangedEventArgs e) { ListView lv = (ListView)sender; selectedBillable = (BillingEntry)lv.SelectedItem; }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "resource")] HttpRequest req, [CosmosDB( databaseName: DatabaseName, collectionName: CollectionName, ConnectionStringSetting = "CosmosDBConnectionString")] DocumentClient documentClient, ILogger log, ExecutionContext context) { // Authorize the request based on the sig parameter var sig = req.Query["sig"]; var config = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory) .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .Build(); if (!config["URL_SIGNATURE"].Equals(sig, StringComparison.OrdinalIgnoreCase)) { log.LogError($"Unexpected or missing 'sig' parameter value '{sig}'"); return(new UnauthorizedResult()); } using (var streamReader = new StreamReader(req.Body)) { var requestBody = await streamReader .ReadToEndAsync() .ConfigureAwait(continueOnCapturedContext: false); log.LogTrace($"Notification payload: {requestBody}"); var deserializationErrors = new List <string>(); var notificationDefinition = JsonConvert.DeserializeObject <NotificationDefinition>( value: requestBody, settings: new JsonSerializerSettings { Error = delegate(object sender, ErrorEventArgs args) { deserializationErrors.Add(args.ErrorContext.Error.Message); args.ErrorContext.Handled = true; } }); if (notificationDefinition == null || deserializationErrors.Any()) { return(new BadRequestObjectResult($"Failed to deserialize request body. Errors: {String.Join(';',deserializationErrors)}")); } if (notificationDefinition.Plan != null) { // If provisioning of a marketplace application instance is successful, we persist a billing entry to be picked up by the chron metric emitting job if (notificationDefinition.EventType == "PUT" && notificationDefinition.ProvisioningState == "Succeeded" && notificationDefinition.BillingDetails?.ResourceUsageId != null) { var billingEntry = new BillingEntry { // CosmosDB does not support forward slashes in the id. id = notificationDefinition.ApplicationId.Replace("/", "|"), planId = notificationDefinition.Plan.Name, resourceUsageId = notificationDefinition.BillingDetails.ResourceUsageId }; await documentClient .UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName), billingEntry) .ConfigureAwait(continueOnCapturedContext: false); log.LogTrace($"Successfully inserted the entry in CosmosDB for the application {notificationDefinition.ApplicationId}"); } else if (notificationDefinition.EventType == "DELETE" && notificationDefinition.ProvisioningState == "Deleted" && notificationDefinition.Plan != null) { // On successful deletion of a marketplace application instance try to delete a billing entry in case one was created var docLink = UriFactory.CreateDocumentUri(DatabaseName, CollectionName, notificationDefinition.ApplicationId.Replace("/", "|")); var requestOptions = new RequestOptions { PartitionKey = new PartitionKey(notificationDefinition.Plan.Name) }; try { await documentClient .DeleteDocumentAsync(docLink, requestOptions) .ConfigureAwait(continueOnCapturedContext: false); log.LogTrace($"Successfully deleted the entry in CosmosDB for the application {notificationDefinition.ApplicationId}"); } catch (DocumentClientException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { log.LogTrace($"There was no entry in CosmosDB for the deleted application {notificationDefinition.ApplicationId}"); } } } } return(new OkResult()); }