Exemple #1
0
 static void lmcomAddAdmin(Container db, string email, string password, string firstName, string lastName) {
   var user = new Users() { EMail = email, Password = password, Created = DateTime.UtcNow, OtherType = 10, FirstName = firstName, LastName = lastName, Roles = (int)Role.All, };
   db.Users.Add(user);
   var company = new Companies() { Title = "Company " + lastName, Created = DateTime.UtcNow };
   db.Companies.Add(company);
   var dep = new CompanyDepartments() { Title = company.Title, Company = company };
   db.CompanyDepartments.Add(dep);
   var compUser = new CompanyUsers() { Company = company, User = user, Created = DateTime.UtcNow/*, RolesEx = (long)CompRole.All*/, CompanyDepartment = dep };
   setRolesEx(compUser, (long)CompRole.All);
   db.CompanyUsers.Add(compUser);
   //@PRODID
   string[] ignoreUserLic = new string[] { "/lm/prods_lm_blcourse_english/", "/lm/prods_lm_blcourse_french/", "/lm/prods_lm_blcourse_german/" };
   foreach (var prodId in new string[] { 
     //"/data/xmlsource/simpleenglish/", "/data/xmlsource/simplespanish/", 
     //"/data/xmlsource/docexamples/", "/data/xmlsource/TestProduct/",
     //"/lm/EnglishE_0_10/", "/lm/English_0_10/", "/lm/German_0_5/", "/lm/Spanish_0_6/", "/lm/French_0_6/", "/lm/Italian_0_6/", "/lm/Russian_0_3/",
     //"/lm/EnglishE_0_1/", "/lm/Spanish_0_1/", 
     //"/grafia/od1_8/", "/grafia/od1_administrativ/",
     //"/skrivanek/prods/etestme-std/english/a1/", "/skrivanek/prods/etestme-comp/english/a1/", "/skrivanek/prods/etestme-comp/english/all/", 
     //"/skrivanek/prods/etestme-comp/french/all/",
     //"/skrivanek/prods/etestme-comp/german/all/","/skrivanek/prods/etestme-comp/russian/all/",
     //"/skrivanek/prods/etestme-comp/italian/all/","/skrivanek/prods/etestme-comp/spanish/all/",
     //"/lm/prods/etestme/english/a1/", //"/lm/prods/etestme/english/a1_c2/"
     //Blended
     "/lm/blcourse/schoolmanager.product/",
     "/lm/blcourse/langmastermanager.product/",
     }.Concat(ignoreUserLic).Select(p => p.ToLower())) {
     var compLicence = new CompanyLicences() { Company = company, Days = 100, ProductId = prodId, Created = DateTime.UtcNow };
     db.CompanyLicences.Add(compLicence);
     var courseUser = new CourseUsers() { CompanyUser = compUser, Created = DateTime.UtcNow, ProductId = prodId };
     db.CourseUsers.Add(courseUser);
     if (!ignoreUserLic.Contains(prodId)) {
       var userLicence = new UserLicences() { CompanyLicence = compLicence, CourseUser = courseUser, Started = DateTime.UtcNow, Created = DateTime.UtcNow };
       db.UserLicences.Add(userLicence);
     }
   }
 }
Exemple #2
0
    public static bool adjustCourseUser(Container db, Int64 lmcomUserId, int companyId, string productId, out CourseUsers crsUser, out CompanyUsers compUser) {
      DateTime startDate = DateTime.UtcNow; crsUser = null;

      //adjust CompanyUser
      compUser = db.CompanyUsers.FirstOrDefault(u => u.CompanyId == companyId && u.UserId == lmcomUserId);
      if (compUser == null) {
        var allDeps = db.CompanyDepartments.Where(d => d.CompanyId == companyId).Select(cd => cd.Id).ToArray();
        db.CompanyUsers.Add(compUser = new CompanyUsers() {
          UserId = lmcomUserId,
          CompanyId = companyId,
          Created = DateTime.UtcNow,
          DepartmentId = allDeps.Length == 1 ? (int?)allDeps[0] : null,
        });
      } else
        crsUser = compUser.CourseUsers.FirstOrDefault(cu => cu.ProductId == productId);

      //adjust CourseUser
      if (crsUser == null) {
        db.CourseUsers.Add(crsUser = new CourseUsers() {
          CompanyUser = compUser,
          Created = DateTime.UtcNow,
          ProductId = productId,
        });
        return false;
      }
      return true;
    }
Exemple #3
0
    //static int[] getArchives(Cmd_getArchives par) {
    //  return null;
    //}

    static int createArchive(Cmd_createArchive par) { //par.ProductId musi byt testGlobalAdmin, jinak vznikne neporadek v licencich
      var db = Lib.CreateContext();
      var crsUser = db.CourseUsers.Where(cu => cu.ProductId == par.productId && cu.CompanyUser.CompanyId == par.companyId && cu.CompanyUser.UserId == par.lmcomId).FirstOrDefault();
      if (crsUser == null) return 0;
      crsUser.ProductId = crsUser.ProductId + "|" + crsUser.Id.ToString();
      var licences = crsUser.UserLicences.Skip(1).ToArray(); //vsechny licence mimo prvni...
      if (licences.Length > 0) { //...preved na noveho CrsUsera
        var crsNewUser = new CourseUsers() {
          UserId = crsUser.UserId,
          Created = DateTime.UtcNow,
          ProductId = par.productId,
        };
        db.CourseUsers.Add(crsNewUser);
        foreach (var lic in licences) lic.CourseUser = crsNewUser;
      }
      Lib.SaveChanges(db);
      return crsUser.Id;
    }