Beispiel #1
0
 public static void refresh(CompanyUsers users, UserCompanies comps, string email, string compId, Action<UserCompany, CompanyUser> action) {
   //zajisti existenci propojovacich prvku
   var comp = comps.Companies.FirstOrDefault(u => u.compId == compId);
   if (comp == null) comps.Companies.Add(comp = new UserCompany { compId = compId, Roles = new CompUserRole(), /*Keys = new List<UserKey>(),*/ Products = new List<UserProduct>() });
   var user = users.Users.FirstOrDefault(u => u.EMail == email);
   if (user == null) users.Users.Add(user = new CompanyUser { EMail = email, Roles = new CompUserRole() });
   //modifikuj propojovaci prvky
   action(comp, user);
   //aktualizuj seznamy propojovacich prvku
   if (user.isEmpty()) users.Users = users.Users.Where(u => u.EMail != email).ToList();
   if (comp.isEmpty()) comps.Companies = comps.Companies.Where(c => c.compId != compId).ToList();
 }
 public int enterLicenceKey(string email, ushort compHash, ushort licId, int keyId) {
   var db = driverLow.create();
   var compLicKeys = db.sysRead<Sys_CompShortId>().strDataList;
   var compId = compLicKeys[compHash - 1];
   //var compId = AzureData.Company.findCompanyIdFromHash(db, compHash); if (compId == null) throw new Exception("compId == null");
   var comp = db.compReadForEdit<Company_Licence>(compId);
   var licenceObj = comp.licenceObj;
   var lic = licenceObj.Lics.FirstOrDefault(l => l.LicId == licId);
   if (lic == null) throw new Exception("lic==null");
   var usedLic = lic.Lics.FirstOrDefault(uk => uk.LicKeyId == keyId);
   if (usedLic != null) {
     return usedLic.email == email ? 1 : 2;
   }
   //pouziti licencniho klice
   var user = db.userReadForEdit<User_Company>(email); if (user == null) throw new Exception("user == null");
   var userComps = user.companiesObj;
   lic.Lics.Add(new UsedKey { email = email, LicKeyId = keyId });
   var userComp = userComps.Companies.FirstOrDefault(c => c.compId == comp.compId);
   if (userComp == null) userComps.Companies.Add(userComp = new Admin.UserCompany { compId = comp.compId, Products = new List<UserProduct>() });
   if (lic.isTest) {
     var userProd = new UserProduct { ProductId = lic.ProductId, LicKeyId = keyId };
   } else {
     var userProd = userComp.Products.FirstOrDefault(p => p.ProductId == lic.ProductId);
     if (userProd == null) userComp.Products.Add(userProd = new UserProduct { ProductId = lic.ProductId, Created = LowUtils.nowToNum() });
     userProd.CourseDays += lic.CourseDays;
     //userProd.Keys.Add(new UserKey { /*CompLicKeyId = licenceObj.compLicKeyId,*/ KeyId = keyId, LicId = lic.LicId, Days = lic.Days });
   }
   //save
   db.SaveChanges();
   return 0;
 }