public void OnActivateCommand_Ok() { var path = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "data", "test.license.xml"); var service = Substitute.For <ILicenseService>(); var ctx = Substitute.For <IApplicationContext>(); var model = new LicenseViewModel(service, ctx); var license = License.Load(File.OpenRead(path)); var licenseResult = new LicenseResult(license, null, null); service.RegisterAsync(Arg.Any <Guid>()).Returns(licenseResult); service.ValidateAsync(Arg.Any <bool>()).Returns(licenseResult); var key = new Guid("D65321D5-B0F9-477D-828A-086F30E2BF89"); model.RegisterKey = key.ToString(); model.ActivateCommand.Execute(null); service.Received().RegisterAsync(key); service.Received().ValidateAsync(Arg.Any <bool>()); ctx.Received().SetLicenseKeyAsync(key.ToString()); Assert.Equal(AppLicense.Full, LicenseGlobals.Get()); Assert.False(model.IsBusy); }
public IActionResult Post([FromBody] LicenseViewModel model) { try { if (ModelState.IsValid) { var newLicense = _mapper.Map <LicenseViewModel, CustomerDriverLicense>(model); _repository.AddEntity(newLicense); if (_repository.SaveAll()) { return(Created($"/api/Licenses/{newLicense.ID}", _mapper.Map <CustomerDriverLicense, LicenseViewModel>(newLicense))); } } else { return(BadRequest(ModelState)); } } catch (Exception ex) { _logger.LogError($"Failed to save a new License: {ex}"); } return(BadRequest("Failed to save new License.")); }
public void InitializeTest_Invalid() { var service = Substitute.For <ILicenseService>(); var ctx = Substitute.For <IApplicationContext>(); var model = new LicenseViewModel(service, ctx); var appId = Guid.NewGuid().ToString(); var exception = new Exception("Exception"); var validation = new[] { new GeneralValidationFailure { Message = "Message", HowToResolve = "HowToResolve" } }; var validationResult = new LicenseResult(null, exception, validation); service.ValidateAsync(Arg.Any <bool>()).Returns(validationResult); ctx.GetValueOrDefault(LicenseGlobals.AppId, null).Returns(appId); model.Initialize(); Assert.Null(model.RegisterKey); Assert.Equal("|Message|HowToResolve|Exception|", model.ErrorMessage.Replace("\r\n", "|")); Assert.True(model.ShowError); Assert.Equal("Product Name - Demo", model.Description); Assert.Null(model.LicenseKey); Assert.False(model.ShowActivated); Assert.False(model.IsBusy); }
public async Task <IHttpActionResult> AddLicense([FromBody] LicenseViewModel data) { using (var context = new ConnectContext()) { var client = await context.Clients.Include(x => x.Licenses).FirstOrDefaultAsync(c => c.AccessId == data.AccessId); if (client != null) { var license = new License { Created = DateTime.Now, Expiration = data.Expiration, Key = data.Expiration.Ticks.ToString(CultureInfo.InvariantCulture).TrimEnd(char.Parse("0")), AccessId = Guid.NewGuid() }; client.Licenses.Add(license); await context.SaveChangesAsync(); return(Ok(new LicenseViewModel(license))); } return(BadRequest("Could not find client")); } }
public void InitializeTest_Valid() { var path = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "data", "test.license.xml"); var service = Substitute.For <ILicenseService>(); var ctx = Substitute.For <IApplicationContext>(); var model = new LicenseViewModel(service, ctx); var appId = Guid.NewGuid().ToString(); var license = License.Load(File.OpenRead(path)); var validationResult = new LicenseResult(license, null, null); service.ValidateAsync(Arg.Any <bool>()).Returns(validationResult); ctx.GetValueOrDefault(LicenseGlobals.AppId, null).Returns(appId); model.Initialize(); Assert.Null(model.RegisterKey); Assert.Null(model.ErrorMessage); Assert.False(model.ShowError); Assert.Equal("Product Name - Full", model.Description); Assert.Equal(license.Id.ToString(), model.LicenseKey); Assert.True(model.ShowActivated); Assert.False(model.IsBusy); }
public void OnActivateCommand_Error() { var service = Substitute.For <ILicenseService>(); var ctx = Substitute.For <IApplicationContext>(); var model = new LicenseViewModel(service, ctx); var exception = new Exception("Exception"); var validation = new[] { new GeneralValidationFailure { Message = "Message", HowToResolve = "HowToResolve" } }; var licenseResult = new LicenseResult(null, exception, validation); service.RegisterAsync(Arg.Any <Guid>()).Returns(licenseResult); service.ValidateAsync(Arg.Any <bool>()).Returns(licenseResult); model.Initialize(); var key = new Guid("ae8cdf5f-26b3-4e2f-8e68-6ecc2e73720f"); model.RegisterKey = key.ToString(); model.ActivateCommand.Execute(null); service.Received().RegisterAsync(key); ctx.DidNotReceive().SetLicenseKeyAsync(Arg.Any <string>()); Assert.Equal(AppLicense.Demo, LicenseGlobals.Get()); Assert.Equal("|Message|HowToResolve|Exception|", model.ErrorMessage.Replace("\r\n", "|")); Assert.True(model.ShowError); Assert.False(model.IsBusy); }
public ActionResult ScheduleLicenseApplication(LicenseViewModel licenseModel) { var selectedAadharNumber = licenseModel.SelectedId; var citizenModel = new CitizenViewModel(); var rta = new ASTIRTA(); var pendingCitizen = rta.GetLicensePendingCitizen(selectedAadharNumber); citizenModel.Name = pendingCitizen.Name; citizenModel.Address = pendingCitizen.Address; citizenModel.Contact = pendingCitizen.Contact; citizenModel.DateOfBirth = pendingCitizen.DateOfBirth; citizenModel.FatherName = pendingCitizen.FatherName; citizenModel.Gender = pendingCitizen.Gender; citizenModel.Occupation = pendingCitizen.Occupation; citizenModel.ImagePath = pendingCitizen.ImagePath; citizenModel.PinCode = pendingCitizen.PinCode; citizenModel.SurveyorName = pendingCitizen.SurveyorName; citizenModel.ApplicationNumber = pendingCitizen.ApplicationId; citizenModel.DateOfRegistration = DateTime.Now;//Should be recieved from DB citizenModel.IsPending = pendingCitizen.IsPending; citizenModel.IsLicensePending = pendingCitizen.IsLicensePending; citizenModel.AadharNumber = pendingCitizen.AadharNumber; return(View("CitizenProfile", citizenModel)); }
public async Task <IActionResult> Edit(int id, LicenseViewModel viewModel) { if (ModelState.IsValid) { viewModel.Name = viewModel.Name.Trim(); var license = await _db.LicenseRepository.GetAsync(id); if (license != null) { _mapper.Map(viewModel, license); _db.LicenseRepository.Update(license); await _db.SaveAsync(); return(Redirect("/Admin/License")); } else { return(NotFound()); } } else { return(View(viewModel)); } }
public ActionResult AddLicense(int id) { LicenseViewModel model = new LicenseViewModel(); model.MemberID = id; return(PartialView("_LicenseAdd", model)); }
public ActionResult DeleteLicense(int id, int mid) { LicenseViewModel model = new LicenseViewModel(); model.DeleteLicense(id); return(PartialView("_LicenseSchedule", model.GetLicense(mid))); }
public JsonResult LicenseFilterNextPage(FilterAndSortingOptions filter_template, int SkipCount) { IQueryable <License> licenses = repository.License.GetNotDeletedItems(); licenses = Filtrator.FilterByTemplate <License>(licenses, filter_template); var licenses_vm_list = LicenseViewModel.GetListViewModel(licenses.Skip(SkipCount).Take(60)); return(Json(licenses_vm_list, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> Index() { var licenses = await context.Licenses.ToListAsync(); var model = new LicenseViewModel { Licenses = licenses }; return(View(model)); }
public IActionResult Dashboard(Contractor contractor) { LicenseViewModel licenseViewModel = new LicenseViewModel(); RankViewModel rankViewModel = new RankViewModel(); List <RecordsViewModel> records = new List <RecordsViewModel>(); string contractor_name = contractor.contractors_business_name.ToString(); foreach (var doc in _contractor.getLicenseByName(contractor_name)) { licenseViewModel.address = doc.address; licenseViewModel.city = doc.city; licenseViewModel.state = doc.state; licenseViewModel.license_number = doc.license_number; licenseViewModel.license_type = doc.license_type; licenseViewModel.license_expire_date = doc.license_expire_date; } foreach (var doc in _contractor.getRankByName(contractor_name)) { rankViewModel.rating = doc.rating.ToString(); rankViewModel.total_ratings = doc.total_ratings; rankViewModel.website = doc.website; } foreach (var doc in _projects.Get(contractor_name)) { records.Add(new RecordsViewModel() { permitnum = doc.permitnum, permit_type = doc.permit_type, permit_subtype = doc.permit_subtype, category = doc.category, address_full = doc.address_full, issue_date = doc.issue_date, status = doc.status, status_date = doc.status_date, valuation = doc.valuation, longitude = doc.longitude, latitude = doc.latitude }); } ContractorDashboardViewModel contractorDashboardViewModel = new ContractorDashboardViewModel() { PageTitle = contractor_name, License = licenseViewModel, Rank = rankViewModel, Records = records }; ViewData["Data"] = contractorDashboardViewModel; ViewData["Contractor Name"] = contractorDashboardViewModel.PageTitle.ToString(); ModelState.Clear(); return(View()); }
public LicenseView() { InitializeComponent(); var ctx = new ApplicationContext(); var service = new LicenseService(ctx, LicenseService.CreateHttpClient()); var model = new LicenseViewModel(service, ctx); BindingContext = model; }
public virtual ActionResult GetChildren([DataSourceRequest] DataSourceRequest request, int Id) { LogI("GetChildren, id=" + Id); var items = LicenseViewModel.GetSubLicenses(Db, Id).ToList(); var dataSource = items.ToDataSourceResult(request); return(new JsonResult { Data = dataSource, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public virtual ActionResult GetAllParents([DataSourceRequest] DataSourceRequest request) { LogI("GetAllParents"); var items = LicenseViewModel.GetLicenses(Db).ToList(); var dataSource = items.ToDataSourceResult(request); return(new JsonResult { Data = dataSource, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public ActionResult LicenseDelete(int licenseId) { LicenseViewModel model = new LicenseViewModel(); if (licenseId > 0) { model.DeleteLicense(licenseId); } return(PartialView("_LicenseSchedule")); }
public static bool AdditionSystemRegistration(RegistrationMaster _Reg, LicenseViewModel licvm) { try { return(MainWindow._FactoryConnection.Registration().AdditionalSystemRegistration(_Reg, licvm)); } catch (Exception ex) { return(false); } }
public void ErrorMessageTest() { var service = Substitute.For <ILicenseService>(); var ctx = Substitute.For <IApplicationContext>(); var model = new LicenseViewModel(service, ctx); model.RegisterKey = "fake"; Assert.Equal("Invalid license key.", model.ErrorMessage); Assert.True(model.ShowError); }
public void OnCanActivateCommand() { var service = Substitute.For <ILicenseService>(); var ctx = Substitute.For <IApplicationContext>(); var model = new LicenseViewModel(service, ctx); model.RegisterKey = Guid.NewGuid().ToString(); var result = model.ActivateCommand.CanExecute(null); Assert.True(result); }
public ActionResult Create(int customerId) { var customer = customerService.GetById(customerId); var vm = new LicenseViewModel { CustomerId = customerId, CustomerName = customer.Name }; return(View(vm)); }
private void btnValidate_Click(object sender, RoutedEventArgs e) { txtActivationKey.SelectAll(); string value = Utility.Utility.Decrypt(txtActivationKey.Selection.Text); licvm = Newtonsoft.Json.JsonConvert.DeserializeObject <LicenseViewModel>(value); var _ExistReg = db.RegistrationMasters.Where(w => w.Key == licvm.Key && w.SystemName == licvm.SystemName && w.MacAddress == licvm.MacAddress && w.MobileNo == licvm.MobileNo && w.EmailID == licvm.EmailID && w.Name == licvm.Name).FirstOrDefault(); if (_ExistReg != null) { if (_ExistReg.IsActivated) { licvm.ServiceList = new List <Service>(); licvm.ServiceList.AddRange(db.RegistrationWiseSearchTypes.Join(db.SearchTypeMasters, x => x.SearchTypeID, y => y.SearchTypeID, (x, y) => new { x, y.SearchName }).Where(w => w.x.RegistrationID == _ExistReg.RegistrationID).Select(s => new Service() { ServiceID = s.x.SearchTypeID, IsRequired = s.x.IsRequired, IsActivated = s.x.IsActivated, ServiceName = s.SearchName }).ToList()); licvm.IsActivated = _ExistReg.IsActivated; licvm.ActivationDtTm = _ExistReg.ActivatedDtTm; licvm.ActivationKey = _ExistReg.ActivationKey; licvm.ActivationUptoDtTm = _ExistReg.ActivatedTillDtTm; MessageBox.Show("Same key has been already activated."); MailData(licvm, _ExistReg.RegistrationID); } } else { if (licvm != null) { listBoxSeachType.ItemsSource = licvm.ServiceList; txtFullName.Text = licvm.Name; txtMobileNo.Text = licvm.MobileNo; txtEmailID.Text = licvm.EmailID; txtCompany.Text = licvm.CompanyName; txtLicenseCount.Text = Convert.ToString(licvm.SystemCount); txtActivationKey.IsEnabled = false; btnValidate.IsEnabled = false; _Reg = new RegistrationMaster(); _Reg.Name = licvm.Name; _Reg.MobileNo = licvm.MobileNo; _Reg.EmailID = licvm.EmailID; _Reg.Key = licvm.Key; _Reg.MacAddress = licvm.MacAddress; _Reg.SystemName = licvm.SystemName; _Reg.CompanyName = licvm.CompanyName; _Reg.LicenseCount = licvm.SystemCount; _Reg.IsActive = true; _Reg.CreatedBy = 1; _Reg.CreatedDtTm = DateTime.Now; _Reg.IsSentForRegistration = true; } } }
public ActionResult ScheduleLicenseApplication() { ASTIRTA rta = new ASTIRTA(); var pendingApplications = rta.GetPendingLicenseApplications(); var licenseModel = new LicenseViewModel() { PendingCitizen = pendingApplications, SelectedId = 1 }; return(View(licenseModel)); }
public Tuple <long, LicenseViewModel> GetLicenseWithAssets(long licenseID) { License license = FindById(licenseID); List <Asset> assets = repositoryAssetLicense.AssetsPerLincense(licenseID); LicenseViewModel licenseViewModel = new LicenseViewModel(); licenseViewModel.license = license; licenseViewModel.FileDescription = license.ColFileName; licenseViewModel.assets = assets; return(new Tuple <long, LicenseViewModel>(licenseID, licenseViewModel)); }
public ActionResult Create([Bind(Include = "Id,ProductId,CustomerId,ExpirationInDays")] LicenseViewModel licenseViewEntity) { if (licenseViewEntity.ProductId > 0 && licenseViewEntity.CustomerId > 0 && licenseViewEntity.ExpirationInDays > 0) { var expiration = DateTime.Now.AddDays(licenseViewEntity.ExpirationInDays); licenseViewEntity.Product = db.Products.FirstOrDefault(x => x.Id == licenseViewEntity.ProductId); licenseViewEntity.Customer = db.Customers.FirstOrDefault(x => x.Id == licenseViewEntity.CustomerId); var newLicense = Portable.Licensing.License.New() .WithUniqueIdentifier(Guid.NewGuid()) .As(Portable.Licensing.LicenseType.Standard) .ExpiresAt(expiration) .WithProductFeatures(new Dictionary <string, string> { { "Feature1", "true" }, { "Feature2", "false" }, }) .LicensedTo(licenseViewEntity.Customer.Name, licenseViewEntity.Customer.Email) .CreateAndSignWithPrivateKey(licenseViewEntity.Product.PrivateKey, ConfigRepository.passPhrase); License license = new License(); license.ProductId = licenseViewEntity.ProductId; license.CustomerId = licenseViewEntity.CustomerId; license.Guid = newLicense.Id.ToString(); license.IssueDate = DateTime.Now; license.Expiration = expiration; license.Type = "standard"; license.Signature = newLicense.Signature; //Clear related entities: license.Product = null; license.Customer = null; db.Licenses.Add(license); db.SaveChanges(); //Saving license file var fileName = getLicenseFileName(license); using (var stream = new System.IO.StreamWriter(HttpContext.Server.MapPath(String.Format("{0}{1}", "~/License_files/", fileName)))) { newLicense.Save(stream); stream.Close(); } return(RedirectToAction("Index")); } ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Name", licenseViewEntity.CustomerId); ViewBag.ProductId = new SelectList(db.Products, "Id", "Name", licenseViewEntity.ProductId); return(View(licenseViewEntity)); }
private void btnSubmit_Click(object sender, RoutedEventArgs e) { try { RegistrationGrid.IsEnabled = false; //Registration details to send LicenseViewModel licvm = new LicenseViewModel(); licvm.ServiceList = new List <Service>(); licvm.ServiceList.AddRange(SearchTypeList); licvm.CompanyName = txtCompanyName.Text; licvm.EmailID = txtEmailID.Text; licvm.Key = Guid.NewGuid().ToString(); licvm.MacAddress = AppUtility.GetMachineData("MACAddress"); licvm.MobileNo = txtMobileNumber.Text; licvm.Name = txtFullName.Text; licvm.SystemCount = Convert.ToInt32(txtLicenseCount.Text); licvm.SystemName = System.Net.Dns.GetHostName(); licvm.IsActivated = false; // Page Event Logger AppUtility.PageEventLogger(PageLogID, "Submit Button", 1, "Registration Button Click Started", "Normal"); //Registeration of Client Int64 RegistrationID = MainWindow._FactoryConnection.Registration().FirstTimeRegistration(txtCompanyName.Text, Convert.ToInt32(txtLicenseCount.Text), txtEmailID.Text, licvm.Key, licvm.SystemName, licvm.MacAddress, txtFullName.Text, txtMobileNumber.Text, SearchTypeList); // Page Event Logger AppUtility.PageEventLogger(PageLogID, "Submit Button", 1, "Registration Done", "Normal"); if (RegistrationID > 0) { // Page Event Logger AppUtility.PageEventLogger(PageLogID, "Submit Button", 1, "Mailig Process Started", "Normal"); AppUtility.SendRegistrationMail(licvm); } MessageBox.Show("Please send the mail."); Frame MainFrame1 = AppUtility.FindChild <Frame>(Application.Current.MainWindow, "MainFrame"); MainFrame1.Navigate(new System.Uri("Forms/Activation.xaml", UriKind.RelativeOrAbsolute)); // Page Event Logger AppUtility.PageEventLogger(PageLogID, "Submit Button", 1, "Registration Button Click END", "Normal"); } catch (Exception ex) { // Page Event Logger AppUtility.PageEventLogger(PageLogID, "Submit Button", 1, ex.Message + " | " + ex.StackTrace, "Error"); MessageBox.Show("There is some error, Please contact administrator."); } finally { RegistrationGrid.IsEnabled = true; } }
public JsonResult LicenseFilter(FilterAndSortingOptions filter_template) { IQueryable <License> licenses = repository.License.GetNotDeletedItems(); licenses = Filtrator.FilterByTemplate <License>(licenses, filter_template); var licenses_vm_list = LicenseViewModel.GetListViewModel(licenses.Take(60)); FilteredLicenseListViewModel result = new FilteredLicenseListViewModel() { Count = licenses.Count(), license_list = licenses_vm_list }; return(Json(result, JsonRequestBehavior.AllowGet)); }
private License CreateNewLicense(LicenseViewModel model) { var newLicense = new License() { Name = model.Name, DateFrom = model.DateFrom, DateTo = model.DateTo, NumberOfConcurrentUserSessionsAllowed = model.NumberOfConcurrentUserSessionsAllowed, HardwareId = model.HardwareId, Active = true }; return(newLicense); }
public ActionResult Create(LicenseViewModel vm) { if (ModelState.IsValid) { var license = new License(); converter.ViewmodelToEntity(vm, ref license); service.Add(license); return(RedirectToAction("Edit", "Customer", new { id = vm.CustomerId })); } else { return(View(vm)); } }
public IActionResult Edit(long id, long?assetID, LicenseViewModel licenseVeiwModel, [Bind("LicenseID,PurchaseItemID,No,Key,HasCol,ColFileName,ValidityTypeTime,LicenseTypeID,LicenseValidityTypeID,AssetID,StatusID,QtyLimited, ParentLicense")] License license) { if (id != license.LicenseID) { return(NotFound()); } Tuple <string, string, bool> filePath = service.UploadLicenseColPdf(licenseVeiwModel.license.LicenseID, licenseVeiwModel.FileDescription, licenseVeiwModel.File); //add FileName and FilePath to license so that this will be saved to the database license.ColFileName = filePath.Item1; license.ColFilePath = filePath.Item2; license.HasCol = filePath.Item3; if (ModelState.IsValid) { try { service.Update(license); } catch (DbUpdateConcurrencyException) { if (!LicenseExists(license.LicenseID)) { return(NotFound()); } else { throw; } } if (assetID == null) { return(RedirectToAction(nameof(Index))); } return(RedirectToAction("Edit", "Asset", new { id = assetID })); } ViewData["AssetID"] = new List <SelectListItem>(service.GetSelectListAssets()); ViewData["LicenseTypeID"] = new List <SelectListItem>(service.GetSelectListLicenseTypes()); ViewData["LicenseValidityTypeID"] = new List <SelectListItem>(service.GetSelectListLicenseValidityTypes()); ViewData["PurchaseItemID"] = new List <SelectListItem>(service.GetSelectListPurchaseItems()); ViewData["StatusID"] = new List <SelectListItem>(service.GetSelectListStatusLicense()); return(View(license)); }
/// <summary>5 /// Initializes a new instance of the <see cref="LicenseWindow"/> class. /// </summary> /// <param name="viewModel">The view model.</param> public LicenseWindow(LicenseViewModel viewModel) : base(viewModel, DataWindowMode.OkCancel) { InitializeComponent(); if (CatelEnvironment.IsInDesignMode) { return; } LicenseManager.ResourceHelper.EnsureStyles(); this.ApplyIconFromApplication(); this.RemoveCloseButton(); }