/// <summary>Method save the entitlement in the database.</summary>
        /// <param name="entitlementToSave"></param>
        /// <param name="ownerId">The user which created the entity.</param>
        /// <returns></returns>
        public bool SaveEntitlement(EEntitlement entitlementToSave, decimal ownerId)
        {
            if (entitlementToSave == null)
            {
                throw new ArgumentNullException(nameof(entitlementToSave));
            }
            if (ownerId < 1)
            {
                throw new ArgumentNullException(nameof(ownerId), "Creator_id must be greather than 0");
            }

            using (var context = _ContextGenerator.GenerateContext())
            {
                var license = entitlementToSave.ToProductLicense();
                license.ID_User_Creator = ownerId;
                Product_License dbLicense =
                    context.Product_License.FirstOrDefault(l => l.ID_Product_License == license.ID_Product_License);
                {
                    if (dbLicense != null)
                    {
                        license.Date_Created = dbLicense.Date_Created;
                        context.Product_License.AddOrUpdate(license);
                    }
                    else
                    {
                        context.Product_License.Add(license);
                    }
                    context.SaveChanges();
                    entitlementToSave.Id = license.ID_Product_License;
                }
            }
            return(true);
        }
Example #2
0
 public EditEntitlementModel LoadEntitlement(EEntitlement entitlement)
 {
     EntitlementId = entitlement.Id;
     DateBegin     = entitlement.DateBegin;
     DateEnd       = entitlement.DateEnd;
     DateCreated   = entitlement.DateCreated;
     LicensesCount = entitlement.LicensesCount;
     Details       = entitlement.Details;
     LicTypeId     = entitlement.LicenseTypeId;
     ClientId      = entitlement.ClientId;
     ProjectId     = entitlement.ProjectId;
     return(this);
 }
 public ActionResult SaveEntitlement(EditEntitlementModel model)
 {
     if (model.DateBegin > model.DateEnd)
     {
         ModelState.AddModelError("DateEnd", "The end date must be greather then begin date");
     }
     if (ModelState.IsValid)
     {
         CheckUserAuthorization();//Check this user before save
         EEntitlement ent = model.ToEEntitlement();
         EntitlementsProvider.SaveEntitlement(ent, UserStateManager.GetUserIdFromCookies(Request));
         model.EntitlementId = ent.Id;
         return(RedirectToAction("EditEntitlement", "Entitlement", new { entitlementId = model.EntitlementId }));
     }
     LoadThirdElementsData(model);
     return(View("EditEntitlement", model));
 }
Example #4
0
        public EEntitlement ToEEntitlement()
        {
            EEntitlement ent = new EEntitlement()
            {
                Id            = this.EntitlementId > 0 ? this.EntitlementId : 0,
                ClientId      = ClientId,
                DateBegin     = this.DateBegin,
                DateEnd       = this.DateEnd,
                LicensesCount = this.LicensesCount,
                LicenseTypeId = LicTypeId,
                ProjectId     = this.ProjectId
            };

            if (DateCreated == default(DateTime))
            {
                ent.DateCreated = DateTime.Now;
            }
            return(ent);
        }
 public static Product_License ToProductLicense(this EEntitlement entitlement)
 {
     if (entitlement == null)
     {
         return(null);
     }
     return(new Product_License()
     {
         ID_Product_License = entitlement.Id > 0 ? entitlement.Id : 0,
         Date_Begin = entitlement.DateBegin,
         Date_End = entitlement.DateEnd,
         Date_Created = entitlement.DateCreated,
         License_Count = entitlement.LicensesCount,
         Details = entitlement.Details,
         ID_Client = entitlement.ClientId,
         ID_License_Type = entitlement.LicenseTypeId,
         ID_Project = entitlement.ProjectId
     });
 }
Example #6
0
        public List <EEntitlement> GetEntitlementsForProject(decimal projectId)
        {
            if (projectId < 1)
            {
                throw new ArgumentException("The project id must be greather than 0.");
            }
            List <EEntitlement> entitlements = new List <EEntitlement>();

            using (var context = _ContextGenerator.GenerateContext())
            {
                var dbEntitlements = (from e in context.Product_License
                                      where e.ID_Project == projectId
                                      select e).ToList();
                if (dbEntitlements?.Count > 0)
                {
                    var project = (from p in context.Project
                                   where p.ID_Project == projectId
                                   select p).First().ToEProject();
                    IEnumerable <EClient>      clients      = LoadClients(dbEntitlements);
                    IEnumerable <EUser>        users        = LoadCreators(dbEntitlements);
                    IEnumerable <ELicenseType> licenseTypes = LoadLicenseTypes(dbEntitlements);

                    foreach (var dbEntitlement in dbEntitlements)
                    {
                        EEntitlement entitlement = dbEntitlement.ToEEntitlement();
                        entitlement.Client  = clients.FirstOrDefault(c => c.Id == dbEntitlement.ID_Client);
                        entitlement.Creator = users.FirstOrDefault(c => c.Id == dbEntitlement.ID_User_Creator);
                        entitlement.LicType = licenseTypes
                                              .FirstOrDefault(c => c.Id == dbEntitlement.ID_Product_License);
                        entitlement.Project = project;
                        entitlements.Add(entitlement);
                    }
                }
            }
            return(entitlements);
        }