コード例 #1
0
        public ActionResult Enregistrer()
        {
            try
            {
                Subscription subscription = null;
                SessionManager.Get<Data.Model.Subscription>(SouscriptionBL.SubscriptionSession, out subscription);

                if (subscription != null)
                {
                    using (var context = new UpsilabEntities())
                    {
                        //Save the souscription to table.
                        subscription.IdFirmInstitution = SessionManager.GetFirmInstitutionSession().idFirmInstitution;
                        subscription.DateCreated = DateTime.Now;
                        subscription.DateExpired = subscription.Duration.HasValue ? subscription.DateCreated.AddYears(subscription.Duration.Value) : DateTime.Now;
                        context.Subscription.AddObject(subscription);

                        #region Renouvellement licences
                        //Get licences to renew from session
                        IList<License> lstLicensesToRenew = new List<License>();
                        SessionManager.Get<IList<Data.Model.License>>(LicenseBL.LicenseListSession, out lstLicensesToRenew);

                        if (lstLicensesToRenew != null)
                        {
                            foreach (var license in lstLicensesToRenew)
                            {
                                LicenseRenewalLog licenseRenewalLog = new LicenseRenewalLog()
                                {
                                    DateCreated = DateTime.Now,
                                    idLicense = license.idLicense,
                                    idSubscription = subscription.IdSubscription,
                                };

                                context.LicenseRenewalLog.AddObject(licenseRenewalLog);
                            }
                        }
                        #endregion

                        context.SaveChanges();
                    }

                    //Si tout est ok : clear les sessions
                    if (SessionManager.Exists(LicenseBL.LicenseListSession))
                    {
                        SessionManager.Clear(LicenseBL.LicenseListSession);
                    }

                    SessionManager.Clear(SouscriptionBL.SubscriptionSession);

                    return RedirectToAction("Aller", "Paiement", new { id = subscription.IdSubscription });
                }
                else
                {
                    ViewBag.Info = LanguageData.GetContent("aucun_logiciel_selectionné");
                }
            }
            catch (Exception ex)
            {
                ViewBag.Info = LanguageData.GetContent("erreur_catch") + ex.Message;
            }

            return View();
        }
コード例 #2
0
        public static void AddLicenseRenewalLog(IList<Data.Model.License> lstLicencesToRenew, int idSubscription)
        {
            using (Data.Model.UpsilabEntities createContext = new UpsilabEntities())
            {
                foreach (Data.Model.License l in lstLicencesToRenew)
                {
                    LicenseRenewalLog licLog = new LicenseRenewalLog()
                    {
                        idLicense = l.idLicense,
                        idSubscription = idSubscription,
                        DateCreated = DateTime.Now,
                    };

                    createContext.LicenseRenewalLog.AddObject(licLog);
                }

                createContext.SaveChanges();
            }
        }