Пример #1
0
        public void UpdateFulfillment(FulfillmentInfo fulfillmentInfo, KeyStoreContext context = null)
        {
            UsingContext(ref context, () =>
            {
                FulfillmentInfo info = context.FulfillmentInfoes.Single(i => i.FulfillmentNumber == fulfillmentInfo.FulfillmentNumber);
                if (!ValidateStatusTransition(info.FulfillmentStatus, fulfillmentInfo.FulfillmentStatus))
                    throw new ApplicationException(string.Format("Cannot change fulfillment {0} status from {1} to {2}.",
                        info.FulfillmentNumber, info.FulfillmentStatus.ToString(), fulfillmentInfo.FulfillmentStatus.ToString()));

                context.Entry(info).CurrentValues.SetValues(fulfillmentInfo);
                info.ModifiedDateUtc = DateTime.UtcNow;
            });
        }
Пример #2
0
        public void UpdateReturnKeyAck(ReturnReport returnKey, KeyStoreContext context)
        {
            UsingContext(ref context, () =>
            {
                context.Configuration.AutoDetectChangesEnabled = false;
                UpdateReturnKeyAck(context, returnKey);

                foreach (ReturnReportKey key in returnKey.ReturnReportKeys)
                {
                    context.ReturnReportKeys.Attach(key);
                    context.Entry(key).State = EntityState.Modified;
                }
            });
        }
Пример #3
0
 public void InsertCbrAndCbrKeys(Cbr cbr, KeyStoreContext context = null)
 {
     UsingContext(ref context, () =>
     {
         context.Configuration.AutoDetectChangesEnabled = false;
         cbr.CreatedDateUtc = cbr.ModifiedDateUtc = DateTime.UtcNow;
         context.Cbrs.Add(cbr);
         foreach (var key in cbr.CbrKeys)
         {
             context.CbrKeys.Add(key);
         }
         context.SaveChanges();
     });
 }
Пример #4
0
 private void InsertRole(User user, KeyStoreContext context)
 {
     user.Roles.ToList().ForEach(r => context.Roles.Attach(r));
 }
Пример #5
0
 private void InsertHeadQuarter(User user, KeyStoreContext context)
 {
     if (Constants.IsMultipleEnabled)
         user.UserHeadQuarters.ToList().ForEach(u => context.UserHeadQuarters.Add(u));
     else
     {
         if (context.HeadQuarters.Count() > 0)
         {
             var map = new UserHeadQuarter()
             {
                 User = user,
                 HeadQuarterId = context.HeadQuarters.First().HeadQuarterId,
                 IsDefault = true
             };
             context.UserHeadQuarters.Add(map);
         }
     }
 }
Пример #6
0
 private Role GetRole(KeyStoreContext context, int roleId)
 {
     return context.Roles.SingleOrDefault(r=>r.RoleId == roleId);
 }
Пример #7
0
 private void DeleteUserHeadQuarter(int userId, KeyStoreContext context)
 {
     context.UserHeadQuarters
         .Where(hq => hq.UserId == userId).ToList()
         .ForEach(h => context.UserHeadQuarters.Remove(h));
 }
Пример #8
0
 private void DeleteUser(KeyStoreContext context, User userToDelete)
 {
     if (context.Entry(userToDelete).State == EntityState.Detached)
         context.Users.Attach(userToDelete);
     context.Users.Remove(userToDelete);
 }
        private void MappingKeyTypeConfiguration(KeyStoreContext context, int? hqId)
        {
            string hqIdString = GetSearchCriteria(hqId);
            string sql = string.Format(@"SELECT INFO.LicensablePartNumber, EX.KeyType
                                FROM ProductKeyInfo INFO JOIN KeyInfoEx EX ON INFO.ProductKeyID = EX.ProductKeyID
                                WHERE EX.HQID {0}
                                AND NOT EXISTS ( SELECT 1 FROM KeyTypeConfiguration WHERE HeadQuarterId {0} AND LicensablePartNumber = info.LicensablePartNumber)
                                GROUP BY INFO.LicensablePartNumber, EX.KeyType", hqIdString);

            var maps = Select<LicensablePartNumberAndKeyTypeMap>(context, sql).ToList();

            if (maps.Any())
            {
                foreach (var map in maps)
                {
                    KeyTypeConfiguration config = new KeyTypeConfiguration
                    {
                        HeadQuarterId = hqId,
                        LicensablePartNumber = map.LicensablePartNumber,
                        Maximum = MaxKeyCounts,
                        Minimum = MinKeyCounts,
                        KeyType = (KeyType?)map.KeyType
                    };
                    context.KeyTypeConfigurations.Add(config);
                }

                context.SaveChanges();
            }
        }
Пример #10
0
 public void InsertOrUpdateKeySyncNotifiction(List<KeyInfo> keys, KeyStoreContext context)
 {
     UsingContext(ref context, () =>
     {
         List<KeySyncNotification> dbSyncs = GetKeySyncNotifications(context, keys.Select(k => k.KeyId).ToArray());
         context.Configuration.AutoDetectChangesEnabled = false;
         foreach (var keyInfo in keys)
         {
             KeySyncNotification dbSync = dbSyncs.SingleOrDefault(s => s.KeyId == keyInfo.KeyId);
             if (dbSync == null)
             {
                 context.KeySyncNotifications.Add(new KeySyncNotification()
                 {
                     KeyId = keyInfo.KeyId,
                     KeyState = keyInfo.KeyState,
                     CreateDate = DateTime.UtcNow,
                 });
             }
             else
             {
                 dbSync.KeyState = keyInfo.KeyState;
                 dbSync.CreateDate = DateTime.UtcNow;
                 context.Entry(dbSync).State = EntityState.Modified;
             }
         }
         context.Configuration.AutoDetectChangesEnabled = true;
     });
 }
Пример #11
0
 public ReturnReport GetReturnKey(Guid customerReportUniqueId, KeyStoreContext context)
 {
     return context.ReturnReports.Include("ReturnReportKeys").Where(r => r.ReturnUniqueId == customerReportUniqueId).SingleOrDefault();
 }
Пример #12
0
 public ReturnReport GetReturnKeyByOneKeyID(long keyId, KeyStoreContext context)
 {
     return context.ReturnReports.Include("ReturnReportKeys").Where(r => r.ReturnReportKeys.Where(s => s.KeyId == keyId && s.ReturnReasonCode == null).Count() > 0).SingleOrDefault();
 }
Пример #13
0
 private IQueryable<KeySyncNotification> GetSyncQuery(KeyStoreContext context)
 {
     return (from sync in context.KeySyncNotifications
             select sync);
 }
Пример #14
0
 private List<KeySyncNotification> GetKeySyncNotifications(KeyStoreContext context, long[] keyIds)
 {
     SetupTempKeyIdTable(context, keyIds);
     return (from k in context.KeySyncNotifications
             join t in context.TempKeyId on k.KeyId equals t.KeyId
             select k).ToList();
 }
Пример #15
0
 private IQueryable<KeyInfoEx> GetKeyQuery(KeyStoreContext context)
 {
     return (from key in context.KeyInfoExes
             select key);
 }
Пример #16
0
 private void InsertUser(User user, KeyStoreContext context)
 {
     context.Users.Add(user);
 }
Пример #17
0
 private HeadQuarter GetHeadQuarter(KeyStoreContext context, int id)
 {
     return context.HeadQuarters.SingleOrDefault(hq => hq.HeadQuarterId == id);
 }
Пример #18
0
 private void UpdateCbr(KeyStoreContext context, Cbr cbr)
 {
     context.Cbrs.Attach(cbr);
     context.Entry(cbr).State = EntityState.Modified;
 }
        private List<KeyTypeConfiguration> GetAllKeyTypeConfigurations(KeyStoreContext context, int? hqId)
        {
            string hqIdString = GetSearchCriteria(hqId);
            string sql = string.Format(@"SELECT config.[KeyTypeConfigurationId]
                                          ,config.[HeadQuarterId]
                                          ,config.[LicensablePartNumber]
                                          ,config.[Maximum]
                                          ,config.[Minimum]
                                          ,config.[KeyType] AS KeyTypeId
                                          ,(SELECT COUNT(1) FROM ProductKeyInfo
                                            WHERE LicensablePartNumber = config.LicensablePartNumber and ProductKeyStateID = {0}) AS AvailiableKeysCount
                                      FROM [KeyTypeConfiguration] config
                                      WHERE config.HeadQuarterId {1}
                                      GROUP BY config.[KeyTypeConfigurationId], config.[HeadQuarterId], config.[LicensablePartNumber], config.[Maximum], config.[Minimum], config.[KeyType]
                                      ORDER BY config.[LicensablePartNumber]",
                                        (int)KeyState.Fulfilled, hqIdString);

            var ret = Select<KeyTypeConfigurationWithAvailiableKeysCount>(context, sql);
            return ((IEnumerable)ret).Cast<KeyTypeConfiguration>().ToList();
        }
Пример #20
0
        public void UpdateCbrAck(Cbr cbr, bool IsDuplicateImport = false, KeyStoreContext context = null)
        {
            UsingContext(ref context, () =>
            {
                context.Configuration.AutoDetectChangesEnabled = false;
                UpdateCbr(context, cbr);

                foreach (CbrKey key in cbr.CbrKeys)
                {
                    context.CbrKeys.Attach(key);
                    context.Entry(key).State = EntityState.Modified;
                }
                if (cbr.CbrKeys.Any(k => k.ReasonCode == Constants.CBRAckReasonCode.DuplicateProductKeyId) && !IsDuplicateImport)
                {
                    context.CbrsDuplicated.Add(new CbrDuplicated()
                    {
                        CbrUniqueId = cbr.CbrUniqueId,
                        IsExported = false
                    });
                }
                if (IsDuplicateImport)
                {
                    var delCbr = context.CbrsDuplicated.FirstOrDefault(c => c.CbrUniqueId == cbr.CbrUniqueId);
                    context.CbrsDuplicated.Remove(delCbr);
                }
                context.Configuration.AutoDetectChangesEnabled = true;
            });
        }
Пример #21
0
 private void UpdateReturnKeyAck(KeyStoreContext context, ReturnReport returnKey)
 {
     context.ReturnReports.Attach(returnKey);
     context.Entry(returnKey).State = EntityState.Modified;
 }
Пример #22
0
 private static IQueryable<User> GetQuery(KeyStoreContext context)
 {
     return context.Users.Include("Roles");
 }
Пример #23
0
 private Subsidiary GetSubsidiaryById(KeyStoreContext context, int ssId)
 {
     return context.Subsidiaries.SingleOrDefault(s => s.SsId == ssId);
 }