public void GenerateLicenseValue(LicensePoco licensepoco)
        {
            var tempProduct  = licensepoco.Product;
            var tempCustomer = licensepoco.Customer;

            if (tempProduct == null)
            {
                using (var uow = new UoW())
                {
                    tempProduct = uow.Products.GetByKey(licensepoco.ProductId);
                }
            }

            if (tempCustomer == null)
            {
                using (var uow = new UoW())
                {
                    tempCustomer = uow.Customers.GetByKey(licensepoco.CustomerId);
                }
            }

            var license         = License.New();
            var productFeatures = new Dictionary <string, string>
            {
                { "FirstName", tempCustomer.FirstName },
                { "LastName", tempCustomer.LastName },
                { "Email", tempCustomer.Email }
            };

            if (licensepoco.ExpireDate != null)
            {
                license = license.ExpiresAt((DateTime)licensepoco.ExpireDate);
            }

            if (licensepoco.ExpireVersion != null)
            {
                productFeatures.Add("Version", licensepoco.ExpireVersion.ToString());
            }

            var finalLicense = license.WithUniqueIdentifier(Guid.NewGuid())
                               .As(LicenseType.Standard)
                               .WithMaximumUtilization(1)
                               .WithProductFeatures(productFeatures)
                               .CreateAndSignWithPrivateKey(tempProduct.PrivateKey, tempProduct.PassPhrase);

            licensepoco.Value = finalLicense.ToString();
        }
        public void GenerateLicenseValue(LicensePoco licensepoco)
        {
            var tempProduct = licensepoco.Product;
            var tempCustomer = licensepoco.Customer;
            if (tempProduct == null)
            {
                using (var uow = new UoW())
                {
                    tempProduct = uow.Products.GetByKey(licensepoco.ProductId);
                }
            }

            if (tempCustomer == null)
            {
                using (var uow = new UoW())
                {
                    tempCustomer = uow.Customers.GetByKey(licensepoco.CustomerId);
                }
            }

            var license = License.New();
            var productFeatures = new Dictionary<string, string>
            {
                {"FirstName", tempCustomer.FirstName},
                {"LastName", tempCustomer.LastName},
                {"Email", tempCustomer.Email}
            };

            if (licensepoco.ExpireDate != null)
            {
                license = license.ExpiresAt((DateTime) licensepoco.ExpireDate);
            }

            if (licensepoco.ExpireVersion != null)
            {
                productFeatures.Add("Version", licensepoco.ExpireVersion.ToString());
            }

            var finalLicense = license.WithUniqueIdentifier(Guid.NewGuid())
                .As(LicenseType.Standard)
                .WithMaximumUtilization(1)
                .WithProductFeatures(productFeatures)
                .CreateAndSignWithPrivateKey(tempProduct.PrivateKey, tempProduct.PassPhrase);

            licensepoco.Value = finalLicense.ToString();
        }
예제 #3
0
        // GET: /License/Edit/5
        //public ActionResult Edit(int? id)
        //{
        //    Log.Debug("GET/Edit id:{0}", id.ToString());
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    LicensePoco licensepoco = null;
        //    using (var uow = new UoW())
        //    {
        //        var licensesRepo = uow.GetRepository<ILicensePocoRepository>();
        //        licensepoco = licensesRepo.GetByKey((System.Int32) id);
        //    }
        //    if (licensepoco == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    using (var uow = new UoW())
        //    {
        //        ViewBag.CustomerId = new SelectList(uow.Customers.GetAll().ToList(), "Id", "FirstName");
        //        ViewBag.ProductId = new SelectList(uow.Products.GetAll().ToList(), "Id", "Name");
        //    }
        //    return View(licensepoco);
        //}

        //// POST: /License/Edit/5
        //// To protect from overposting attacks, please enable the specific properties you want to bind to, for
        //// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public ActionResult Edit([Bind(Include = "Id,Value,ExpireVersion,ExpireDate,CustomerId,ProductId,CreatorId,ModificationDate,CreationDate")] LicensePoco licensepoco)
        //{
        //    Log.Debug("POST/Edit");
        //    if (ModelState.IsValid)
        //    {
        //        using (var uow = new UoW())
        //        {
        //            var licensesRepo = uow.GetRepository<ILicensePocoRepository>();

        //            licensesRepo.Update(licensepoco);
        //            uow.SaveChanges();
        //        }
        //    }
        //    using (var uow = new UoW())
        //    {
        //        ViewBag.CustomerId = new SelectList(uow.Customers.GetAll().ToList(), "Id", "FirstName");
        //        ViewBag.ProductId = new SelectList(uow.Products.GetAll().ToList(), "Id", "Name");
        //    }
        //    return View(licensepoco);
        //}

        // GET: /License/Delete/5
        public ActionResult Delete(int?id)
        {
            Log.Debug("GET/Delete Id:{0}, id.ToString()");
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LicensePoco licensepoco = null;

            using (var uow = new UoW())
            {
                var licensesRepo = uow.GetRepository <ILicensePocoRepository>();
                licensepoco = licensesRepo.GetByKey((System.Int32)id);
            }
            if (licensepoco == null)
            {
                return(HttpNotFound());
            }
            return(View(licensepoco));
        }
예제 #4
0
        // GET: /License/Details/5
        public ActionResult Details(int?id)
        {
            Log.Debug("GET/Details id: {0}", id.ToString());
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LicensePoco licensepoco = null;

            using (var uow = new UoW())
            {
                var licensesRepo = uow.GetRepository <ILicensePocoRepository>();
                //  licensepoco = licensesRepo.GetByKey((System.Int32) id); // Geert mayby add include?
                licensepoco = licensesRepo.GetQuery().Include(x => x.Customer).Include(x => x.Product).FirstOrDefault(x => x.Id == (System.Int32)id);
            }
            if (licensepoco == null)
            {
                return(HttpNotFound());
            }
            return(View(licensepoco));
        }
예제 #5
0
        public ActionResult Create([Bind(Include = "Id,Value,ExpireVersion,ExpireDate,CustomerId,ProductId,CreatorId,ModificationDate,CreationDate")] LicensePoco licensepoco)
        {
            Log.Debug("POST/Create");
            if (ModelState.IsValid)
            {
                _licenseGenerationService.GenerateLicenseValue(licensepoco);
                using (var uow = new UoW())
                {
                    var licensesRepo = uow.GetRepository <ILicensePocoRepository>();
                    licensesRepo.Add(licensepoco);
                    uow.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }

            using (var uow = new UoW())
            {
                ViewBag.CustomerId = JsonConvert.SerializeObject(uow.Customers.GetAll().ToList()); // new SelectList(uow.Customers.GetAll().ToList(), "Id", "FirstName");
                ViewBag.ProductId  = JsonConvert.SerializeObject(uow.Products.GetAll().ToList());  //new SelectList(uow.Products.GetAll().ToList(), "Id", "Name");
            }
            return(View(licensepoco));
        }