예제 #1
0
파일: Lib.cs 프로젝트: PavelPZ/REW
    public static bool adjustCourseUser(Container db, Int64 lmcomUserId, int companyId, string productId, out CourseUser crsUser, out CompanyUser 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 CompanyUser() {
          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 CourseUser() {
          CompanyUser = compUser,
          Created = DateTime.UtcNow,
          ProductId = productId,
        });
        return false;
      }
      return true;
    }
예제 #2
0
파일: Login.cs 프로젝트: PavelPZ/NetNew
 public static Users PrepareUser(string email, Container db, bool addCompsRole = false) {
   var res = new Users() { Created = DateTime.UtcNow, EMail = email, VerifyStatus = (short)VerifyStates.prepared, Roles = addCompsRole ? (long)Role.Comps : 0 };
   db.Users.Add(res);
   return res;
 }
예제 #3
0
파일: Lib.cs 프로젝트: PavelPZ/REW
 static void init() {
   if (initialized) return;
   initialized = true;
   Logger.Log(@"Lib.NewData.Container init: Start");
   Database.SetInitializer<Container>(new NewData.Migrations.initializer());
   using (var context = new Container()) context.Database.Initialize(false);
   Logger.Log(@"Lib.NewData.Container init: End");
 } static bool initialized;
예제 #4
0
파일: Lib.cs 프로젝트: PavelPZ/REW
 public static void SaveChanges(Container db) {
   try {
     db.SaveChanges();
   } catch (DbEntityValidationException dbEx) {
     StringBuilder sb = new StringBuilder();
     foreach (var validationErrors in dbEx.EntityValidationErrors) {
       foreach (var validationError in validationErrors.ValidationErrors) {
         sb.AppendFormat("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
         sb.AppendLine();
       }
     }
     throw new Exception(sb.ToString(), dbEx);
   }
 }
예제 #5
0
파일: Admin.cs 프로젝트: PavelPZ/REW
 public static Company createCompany(Container db, string title, User usr, bool isFakePublisherCompany) {
   var compDb = new Company() { Title = title, Created = DateTime.UtcNow }; db.Companies.Add(compDb);
   var dep = new CompanyDepartment() { Title = title, Company = compDb };
   db.CompanyDepartments.Add(dep);
   var compUser = new CompanyUser() { Created = DateTime.UtcNow, Company = compDb, User = usr, RolesEx = (long)(isFakePublisherCompany ? CompRole.All : CompRole.Admin), CompanyDepartment = dep };
   db.CompanyUsers.Add(compUser);
   if (isFakePublisherCompany) usr.MyPublisher = compDb;
   return compDb;
 }
예제 #6
0
파일: Lib.cs 프로젝트: PavelPZ/NetNew
 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);
     }
   }
 }
예제 #7
0
파일: My.cs 프로젝트: PavelPZ/NetNew
 static bool checkRole(Container db, Int64 lmcomUserId, int companyId, CompRole role) {
   var r = db.CompanyUsers.Where(c => c.CompanyId == companyId && c.UserId == lmcomUserId).Select(c => c.Roles).FirstOrDefault();
   return (r & (long)role) == (long)role;
 }