public void ResourceDeleteRootResourceTest() { using (var httpClient = new HttpClient()) { httpClient.Timeout = serviceConfiguration.Manifest.DefaultEndpointTimeout; httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", basicAuthHeaderValue); // Create a subscription context. All resources must be created in the context of a subscription. using (var subscriptionContext = new SubscriptionContext(httpClient, providerNamespace: ManifestFactory.Namespace)) { // Create the resource var firstRootResource = CreateRootResourceDefinition( subscriptionId: subscriptionContext.SubscriptionId, resourceGroup: TestResourceGroup, resourceName: "firstResource"); ResourceDefinition resourceResponse = PutResource( httpClient: httpClient, resourceDefinition: firstRootResource, isCreateRequest: true); Assert.AreEqual(firstRootResource.Id, resourceResponse.Id); // Delete the root resource var response = httpClient.DeleteSync(GetResourceUri(firstRootResource)); Assert.IsTrue(response.IsSuccessStatusCode); } } }
private void Search() { SearchClientViewModel searchContentTemp = new SearchClientViewModel(); searchContentTemp.CollectionOfClients = new ObservableCollection <client>(); using (SubscriptionContext context = new SubscriptionContext()) { if (SelectedParameter == "Nazwa klienta") { //int i = Convert.ToInt32(SearchingPhrase); var result = (from c in context.clients where c.name == SearchingPhrase select c).FirstOrDefault(); client cli = (client)result; searchContentTemp.CollectionOfClients.Add(cli); //foreach (subscription s in result) //{ // CollectionOfClients.Add(s); //System.Windows.MessageBox.Show(s.registration_data.ToString() + s.tariff_id.ToString()); // } } else if (SelectedParameter == "Nr abonamentu") { } } SearchContent = searchContentTemp; }
private void Calculate() { TotalCost = 0; foreach (device dev in CollectionOfDevices) { if (dev.IsChecked) { TotalCost += (double)dev.price * NumberOfDays; } } try { int subscriptionTmp = Convert.ToInt16(SubscriptionId); using (SubscriptionContext context = new SubscriptionContext()) { var result = (from s in context.subscriptions where s.subscriptionId == subscriptionTmp select s).First(); Discount = (double)result.tariff.discount; } TotalCostWithDiscount = Math.Round(TotalCost - TotalCost * 0.01 * Discount, 2); } catch (Exception e) { File.AppendAllText(MainWindowViewModel.PathToLog, e.ToString()); System.Windows.MessageBox.Show("Nie można policzyć wartości. Popraw dane."); } }
public AddSubscriberViewModel() { TypeOfOffer = new ObservableCollection <tariff>(); SaveCommand = new SimpleRelayCommand(Save); using (SubscriptionContext context = new SubscriptionContext()) { foreach (tariff t in context.tariffs) { TypeOfOffer.Add(t); } } using (SubscriptionContext context = new SubscriptionContext()) { var result = (from s in context.subscriptions orderby s.subscriptionId descending select s).FirstOrDefault(); if (result == null) { SubscriptionId = "A1000"; } else { SubscriptionId = (result.subscriptionId + 1).ToString(); } } }
public async Task Should_Add_Subscription_To_Database() { var options = new DbContextOptionsBuilder <SubscriptionContext>() .AddInterceptors(new DomainEventDispatcher(Substitute.For <IMediator>())) .UseSqlServer("Server=localhost;Database=Subscriptions;uid=sa;pwd=yourStrong(!)Password;") .Options; var context = new SubscriptionContext(options); await context.Database.EnsureCreatedAsync(); var product = new Product("Flowers", 10, BillingPeriod.Monthly); var customer = new Customer(new Email("*****@*****.**"), new CustomerName("Hossam", "Barakat")); await context.Products.AddAsync(product); await context.Customers.AddAsync(customer); await context.SaveChangesAsync(); var handler = new SubscribeRequestHandler(context, new SubscriptionAmountCalculator()); await handler.Handle(new SubscribeRequest { CustomerId = customer.Id, ProductId = product.Id }, CancellationToken.None); var subscription = await context.Subscriptions .SingleOrDefaultAsync(x => x.Customer.Id == customer.Id && x.Product.Id == product.Id); subscription.ShouldNotBeNull(); }
//Set a subscription to suspend status (call when user cancel his subscription) public void SuspendSubscription(Subscription Model) { Subscription TargetSubscription; using (var db = new SubscriptionContext()) { TargetSubscription = db.Subscription.Find(Model.UserProfileId); TargetSubscription.Status = "suspended"; db.SaveChanges(); } }
//Set a subscription to inactive status public void CancelSubscription(Subscription Model) { Subscription TargetSubscription; using (var db = new SubscriptionContext()) { TargetSubscription = db.Subscription.Find(Model.UserProfileId); TargetSubscription.Status = "inactive"; db.SaveChanges(); } }
public void SetSubscriptionInactive(int id) { Subscription TargetSubscription; using (var db = new SubscriptionContext()) { TargetSubscription = db.Subscription.Find(id); TargetSubscription.Status = "inactive"; db.Entry(TargetSubscription).State = EntityState.Modified; db.SaveChanges(); } }
public void CreateSub(FormCollection collection) { Subscription NewSubscription; using (var db = new SubscriptionContext()) { NewSubscription = db.Subscription.Create(); NewSubscription.Status = "active"; NewSubscription.Payments = new List <Payment>(); using (var db2 = new PaymentContext()) { Payment FirstPayment = db2.Payment.Create(); FirstPayment.Amount = 15.0f; FirstPayment.Date = DateTime.Now; FirstPayment.Status = "cancelled"; db2.Payment.Add(FirstPayment); Payment SecondPayment = db2.Payment.Create(); SecondPayment.Amount = 15.0f; SecondPayment.Date = DateTime.Now.AddDays(30.0); SecondPayment.Status = "pending"; db2.Payment.Add(SecondPayment); //Store subscription info using (var db3 = new UsersContext()) { UserProfile CurrentUser = db3.UserProfiles.Include("Subscription").First(x => x.UserId.Equals(WebSecurity.CurrentUserId)); CurrentUser.Subscription = NewSubscription; NewSubscription.Payments.Add(FirstPayment); NewSubscription.Payments.Add(SecondPayment); NewSubscription.UserProfile = CurrentUser; NewSubscription.UserProfileId = CurrentUser.UserId; NewSubscription.CreditCard = collection["CreditCard"]; NewSubscription.CVVCode = collection["CVVCode"]; NewSubscription.CardNumber = collection["CardNumber"]; NewSubscription.Zip = collection["Zip"]; NewSubscription.BillingAddress = collection["BillingAddress"]; NewSubscription.Status = "active"; NewSubscription.ExpirationDate = DateTime.Parse(collection["ExpirationDate"]); db3.SaveChanges(); } // db2.SaveChanges(); // db.Subscription.Add(NewSubscription); // db.SaveChanges(); } } }
//Get the subscription of an user public Subscription GetSub(int id) { Subscription MySub; string CifratedNumber; using (var db = new SubscriptionContext()) { MySub = db.Subscription.Find(id); CifratedNumber = "****-****-****-" + MySub.CardNumber.Substring(15, 4); MySub.CardNumber = CifratedNumber; MySub.CVVCode = "***"; return(MySub); } }
//Update billing information of the user public void UpdatePaymentInfo(Subscription Model) { Subscription TargetSubscription; using (var db = new SubscriptionContext()) { TargetSubscription = db.Subscription.Find(WebSecurity.CurrentUserId); TargetSubscription.BillingAddress = Model.BillingAddress; TargetSubscription.CardNumber = Model.CardNumber; TargetSubscription.CVVCode = Model.CVVCode; TargetSubscription.ExpirationDate = Model.ExpirationDate; TargetSubscription.Zip = Model.Zip; db.SaveChanges(); } }
//Get the payment list of the current user public List <Subscription> GetAll() { List <Subscription> MySubs; using (var db = new SubscriptionContext()) { MySubs = db.Subscription.Include("Payments").Where(x => x.UserProfileId.Equals(WebSecurity.CurrentUserId)).ToList(); foreach (var sub in MySubs) { sub.CardNumber = "****-****-****-" + sub.CardNumber.Substring(15, 4); sub.CVVCode = "***"; } return(MySubs); } }
//Register a new subscription public void CreateSub() { Subscription NewSubscription; using (var db = new SubscriptionContext()) { NewSubscription = db.Subscription.Create(); NewSubscription.Status = "active"; NewSubscription.Payments = new List <Payment>(); using (var db2 = new PaymentContext()) { Payment FirstPayment = db2.Payment.Create(); FirstPayment.Amount = 15.0f; FirstPayment.Date = DateTime.Now; FirstPayment.Status = "cancelled"; // FirstPayment.Subscription = NewSubscription; // FirstPayment.SubscriptionId = NewSubscription.UserProfileId; db2.Payment.Add(FirstPayment); Payment SecondPayment = db2.Payment.Create(); SecondPayment.Amount = 15.0f; SecondPayment.Date = DateTime.Now.AddDays(30.0); SecondPayment.Status = "pending"; // SecondPayment.Subscription = NewSubscription; // SecondPayment.SubscriptionId = NewSubscription.UserProfileId; db2.Payment.Add(SecondPayment); //Store subscription info using (var db3 = new UsersContext()) { UserProfile CurrentUser = db3.UserProfiles.Include("Subscription").First(x => x.UserId.Equals(WebSecurity.CurrentUserId)); CurrentUser.Subscription = NewSubscription; NewSubscription.Payments.Add(FirstPayment); NewSubscription.Payments.Add(SecondPayment); NewSubscription.UserProfile = CurrentUser; NewSubscription.UserProfileId = CurrentUser.UserId; db3.SaveChanges(); } db2.SaveChanges(); db.Subscription.Add(NewSubscription); db.SaveChanges(); } } }
public void ResourceCreateNestedResourceTest() { using (var httpClient = new HttpClient()) { httpClient.Timeout = serviceConfiguration.Manifest.DefaultEndpointTimeout; httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", basicAuthHeaderValue); // Create a subscription context. All resources must be created in the context of a subscription. using (var subscriptionContext = new SubscriptionContext(httpClient, providerNamespace: ManifestFactory.Namespace)) { // Create the resource var firstRootResource = CreateRootResourceDefinition( subscriptionId: subscriptionContext.SubscriptionId, resourceGroup: TestResourceGroup, resourceName: "firstResource"); ResourceDefinition resourceResponse = PutResource( httpClient: httpClient, resourceDefinition: firstRootResource, isCreateRequest: true); Assert.AreEqual(firstRootResource.Id, resourceResponse.Id); // Create the first nested resource var nestedResource1 = CreateNestedResourceDefinition( subscriptionId: subscriptionContext.SubscriptionId, resourceGroup: TestResourceGroup, resourceName: "nestedResource1", parentResource: firstRootResource); resourceResponse = PutResource( httpClient: httpClient, resourceDefinition: nestedResource1, isCreateRequest: true); Assert.AreEqual(nestedResource1.Id, resourceResponse.Id); // Create the second nested resource var nestedResource2 = CreateNestedResourceDefinition( subscriptionId: subscriptionContext.SubscriptionId, resourceGroup: TestResourceGroup, resourceName: "nestedResource2", parentResource: firstRootResource); resourceResponse = PutResource( httpClient: httpClient, resourceDefinition: nestedResource2, isCreateRequest: true); Assert.AreEqual(nestedResource2.Id, resourceResponse.Id); } } }
public RentTabViewModel() { RentDateStart = DateTime.Now; RentDateEnd = DateTime.Now; CalculateCommand = new SimpleRelayCommand(Calculate); RentCommand = new SimpleRelayCommand(Rent); CollectionOfDevices = new ObservableCollection <device>(); //dadanie urządzeń do listy urządzeń wyświetlanych na liście dostępnych do wypozyczenia using (SubscriptionContext context = new SubscriptionContext()) { //var result = (from d in context.devices select d).ToList(); //porównanie daty zwrotu z datą dzisiejszą, //jeśli dzisiaj powinien być oddany to będzie już dostępny na liście foreach (rent r in context.rents) { if (r.date_of_return < DateTime.Now || r.date_of_rent > DateTime.Now) { //pobranie z listy wypozyczen-urzadzen urządzenie, ktore jest aktualanie niezajęte var result2 = (from dr in context.devices_rents where r.rentId == dr.rent_id select dr.device).First(); //zmienna tymczasowa potrzebna do zaktualizowania statusu wypozyczenia device deviceToChangeIsRentedStatus = (device)result2; //context.devices.Attach(deviceToChangeIsRentedStatus); deviceToChangeIsRentedStatus.is_rented = false; } } context.SaveChanges(); var result = (from d in context.devices select d).ToList(); //odrzucenie urządzeń ktore sa aktualnie wypozyczone foreach (device dev in result) { if (!dev.is_rented) { CollectionOfDevices.Add(dev); } } } }
private void Save() { //dodawanie urządzenia do bazy //tworzenie obiektów i przypisanie im wartości z wypełnionego formularza genre tmpGenre = new genre(); tmpGenre.genre_name = KindOfDevice.ToLower(); device tmpDevice = new device(); tmpDevice.genre = tmpGenre; tmpDevice.manufacturer_name = ManufacturerName.ToLower(); tmpDevice.model_name = ModelName.ToLower(); tmpDevice.serial_number = SerialNumber.ToLower(); try { CostPerDay = CostPerDay.Replace(".", ","); tmpDevice.price = Convert.ToDouble(CostPerDay); } catch (Exception e) { File.AppendAllText(MainWindowViewModel.PathToLog, e.ToString()); System.Windows.MessageBox.Show("Zła wartość liczbowa"); return; } try { using (SubscriptionContext context = new SubscriptionContext()) { context.devices.Add(tmpDevice); context.SaveChanges(); } System.Windows.MessageBox.Show("Dodano urządzenie do bazy."); } catch (Exception e) { File.AppendAllText(MainWindowViewModel.PathToLog, e.ToString()); System.Windows.MessageBox.Show("Nie dodano urządzenia do bazy."); } }
public void happy_case_device() { var msg = JsonConvert.SerializeObject(new { connect = new { device_id = "dev", device_name = "name" }, subscribe = new { devices = true } }); SubscriptionContext ctx = null; handler.Subscribing += (s, e) => { ctx = e.Ctx; }; handler.HandleMessage(svc.Object, new WebSocketSharp.MessageEventArgs(msg)); Assert.AreEqual("name", ctx.device_name); Assert.AreEqual("dev", ctx.device_id); Assert.AreEqual(false, ctx.subscribe_files); Assert.AreEqual(false, ctx.subscribe_labels); Assert.AreEqual(true, ctx.subscribe_devices); }
//Dodanie abonamentu klienta private void Save() { try { SubscriptionContext context = new SubscriptionContext(); subscription subscript = new subscription(); subscript.registration_data = DateTime.Now; subscript.tariff = SelectedOffer; context.subscriptions.Add(subscript); context.SaveChanges(); MessageBox.Show("Dodano abonament."); } catch (Exception ex) { File.AppendAllText(MainWindowViewModel.PathToLog, ex.ToString()); MessageBox.Show("Błąd! Nie udało się dodać abonamentu.", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error); } }
public async Task Should_Add_Subscription_To_Database() { var options = new DbContextOptionsBuilder <SubscriptionContext>() .UseSqlServer("Server=localhost;Database=Subscriptions;uid=sa;pwd=yourStrong(!)Password;") .Options; var context = new SubscriptionContext(options); await context.Database.EnsureCreatedAsync(); var customer = new Customer { Id = Guid.NewGuid(), Email = "*****@*****.**", FirstName = "Hossam", LastName = "Barakat" }; await context.Customers.AddAsync(customer); var product = new Product { Id = Guid.NewGuid(), Name = "Weekly Bunch", Amount = 10, BillingPeriod = BillingPeriod.Monthly }; await context.Products.AddAsync(product); await context.SaveChangesAsync(); var sut = new SubscribeRequestHandler(context, Substitute.For <IEmailSender>()); var subscribeRequest = new SubscribeRequest { CustomerId = customer.Id, ProductId = product.Id }; await sut.Handle(subscribeRequest, CancellationToken.None); var subscription = await context.Subscriptions .SingleOrDefaultAsync(x => x.Customer.Id == customer.Id && x.Product.Id == product.Id); subscription.ShouldNotBeNull(); }
public DeleteDeviceViewModel() { CollectionOfDevices = new ObservableCollection <device>(); using (SubscriptionContext context = new SubscriptionContext()) { try { foreach (device dev in context.devices) { CollectionOfDevices.Add(dev); } } catch (Exception e) { File.AppendAllText(MainWindowViewModel.PathToLog, e.ToString()); } } SelectDeviceCommand = new SimpleRelayCommand(SelectDevice); }
//wybór i usunięcie z bazy urządzenia wybranego z listy private void SelectDevice() { using (SubscriptionContext context = new SubscriptionContext()) { try { MessageBoxResult mr = MessageBox.Show("Czy na pewno usunąć to urządzenie?", "Pytanie", MessageBoxButton.YesNo); if (mr == MessageBoxResult.Yes) { context.devices.Attach(SelectedDevice); context.devices.Remove(SelectedDevice); context.SaveChanges(); } MessageBox.Show("Usunięto urządzenie z bazy."); CollectionOfDevices.Remove(SelectedDevice); } catch (Exception e) { File.AppendAllText(MainWindowViewModel.PathToLog, e.ToString()); MessageBox.Show("Błąd! Nie usunięto urządzenia."); } } }
private void SaveTariff() { if (!string.IsNullOrEmpty(NameOfTariff)) { try { SubscriptionContext context = new SubscriptionContext(); tariff TariffToAdd = new tariff(); TariffToAdd.name_tarriff = NameOfTariff; TariffToAdd.number_of_calling = NumberOfPhones; TariffToAdd.discount = Discount; context.tariffs.Add(TariffToAdd); context.SaveChanges(); System.Windows.MessageBox.Show("Taryfa została poprawnie dodana do bazy", "Komunikat"); } catch (Exception ex) { File.AppendAllText(MainWindowViewModel.PathToLog, ex.ToString()); } } }
//Check if the subscription has expired public void CheckSubscription(int id) { Subscription subscription; using (var db = new SubscriptionContext()) { subscription = db.Subscription.Include("Payments").First(x => x.UserProfileId.Equals(id)); switch (subscription.Status) { case "inactive": if (!HasOverduePayment(subscription)) { ReactiveSubscription(id); } break; case "active": if (HasOverduePayment(subscription)) { SetSubscriptionInactive(id); } else { if (!HasPendingPayment(subscription)) { GenerateNextPayment(); } if (subscription.ExpirationDate.CompareTo(DateTime.Now) < 1) { SuspendSubscription(subscription); } } break; } } }
public IHttpActionResult Post([FromBody] SubscriberIn data) { // Validate subscriber input data if (!ModelState.IsValid) { return(BadRequest("Invalid data")); } // Persist subscriber data in database // TODO: implement through DI var subscriberId = 0; try { using (SubscriptionContext dbContext = new SubscriptionContext()) { Subscriber subscriber = new Subscriber() { Name = data.Name, Email = data.Email, CreateDate = DateTime.Now }; dbContext.Subscribers.Add(subscriber); dbContext.SaveChanges(); subscriberId = subscriber.Id; } } catch (Exception) { // TODO: log error throw; } return(Ok(subscriberId)); }
public GetActiveSubscriptionsQueryHandler(SubscriptionContext context) { _context = context; }
public ListSignalRConnectionsQueryHandler(SubscriptionContext context) { _context = context; }
public SetPreferencesCommandHandler(SubscriptionContext context) { _context = context; }
public SubscribeRequestHandler(SubscriptionContext subscriptionContext, IEmailSender emailSender) { _subscriptionContext = subscriptionContext; _emailSender = emailSender; }
public BindConnectionToUserCommandHandler(SubscriptionContext context) { _context = context; }
public SubscriptionStorage(IRandomStringGenerator rsg, SubscriptionContext db) { _rsg = rsg; _db = db; }