コード例 #1
0
        /// <summary>
        /// This method saves new license details.
        /// </summary>
        /// <param name="license">Details of the license.</param>
        /// <returns></returns>
        public ResultStatus SaveLicense(BusinessEntities.License license)
        {
            try
            {
                using (var lic = new LicenseManagementMVCEntities())
                {
                    var putlicense = new Data.Model.License()
                    {
                        SoftwareId   = license.SoftwareId,
                        LicenseCount = license.LicenseCount,
                        LicenseKey   = license.LicenseKey
                    };

                    try
                    {
                        var existingLicense = lic.Licenses.Where(o => o.SoftwareId == license.SoftwareId).Select(o => o.LicenseId).FirstOrDefault();
                        lic.Licenses.Add(putlicense);
                        lic.SaveChanges();
                    }
                    catch (Exception)
                    {
                        return(ResultStatus.QueryNotExecuted);
                    }
                }
            }
            catch (Exception)
            {
                return(ResultStatus.ConnectionError);
            }
            return(ResultStatus.Success);
        }
コード例 #2
0
        public static void GenerateLicense(FirmInstitution pFirm, Subscription pSub)
        {
            LicenseType licLAB = LicenseTypeBL.GetLicenseTypeeByName(LicenseTypeBL.LabApplication);
            LicenseType licReport = LicenseTypeBL.GetLicenseTypeeByName(LicenseTypeBL.RecueilApplication);

            List<int> lstLicenseType = new List<int>();
            List<string> lstLicensePrefixe = new List<string>();
            switch (pSub.Application)
            {
                case "Lab":
                    lstLicenseType.Add(licLAB.idLicenseType);
                    lstLicensePrefixe.Add("L");
                    break;
                case "Recueil":
                    lstLicenseType.Add(licReport.idLicenseType);
                    lstLicensePrefixe.Add("R");
                    break;
                case "Recueil+Lab":
                    lstLicenseType.Add(licLAB.idLicenseType);
                    lstLicenseType.Add(licReport.idLicenseType);
                    lstLicensePrefixe.Add("L");
                    lstLicensePrefixe.Add("R");
                    break;
            }

            using (UpsilabEntities context = new UpsilabEntities())
            {
                for (int j = 0; j < lstLicenseType.Count; j++)
                {
                    for (int i = 1; i <= pSub.UserCount; i++)
                    {
                        Upsilab.Data.Model.License li = new Data.Model.License();
                        li.idLicense = Guid.NewGuid();
                        li.DateCreated = DateTime.Now;
                        li.DateExpired = pSub.DateExpired;
                        li.idLicenseType = lstLicenseType[j];
                        li.IsValid = true;
                        li.IdSubscription = pSub.IdSubscription;
                        li.LicenseKey = GenerateLicenseKey(pFirm.idFirmInstitution, lstLicensePrefixe[j], pSub.DateCreated, i);
                        context.License.AddObject(li);
                    }
                }
                context.SaveChanges();

            }
        }