Example #1
0
    public static keysFromCompanyTitleResult keysFromCompanyTitle(string companyTitle) {
      var db = NewData.Lib.CreateContext();
      if (companyTitle.EndsWith(" *")) companyTitle = companyTitle.Substring(0, companyTitle.Length - 2);
      var demoCompanyTitle = companyTitle + " *";
      long hash = demoCompanyTitle.GetHashCode(); var host = "blend." + hash;
      var company = db.Companies.FirstOrDefault(c => c.ScormHost == host);
      UserLicence lSpravce = null; UserLicence lStudent = null; UserLicence lUcitel = null; UserLicence lStudentDe = null; UserLicence lUcitelDe = null;
      User uSpravce = null; User uStudent = null; User uUcitel = null; User uStudentDe = null; User uUcitelDe = null;
      var result = new keysFromCompanyTitleResult() { companyTitle = demoCompanyTitle };
      if (company == null) {
        db.Companies.Add(company = new Company() { Title = demoCompanyTitle, Created = DateTime.UtcNow, ScormHost = host });
        var dep = new CompanyDepartment() { Title = company.Title, Company = company };
        db.CompanyDepartments.Add(dep);

        CompanyLicence schoolManLic = null; CompanyLicence englishLic = null;
        foreach (var prodId in new string[] { "/lm/blcourse/schoolmanager.product/", "/lm/prods_lm_blcourse_english/", "/lm/prods_lm_blcourse_french/", "/lm/prods_lm_blcourse_german/" }) {
          var compLicence = new CompanyLicence() { Company = company, Days = 100, ProductId = prodId, Created = DateTime.UtcNow, LastCounter = 10 };
          if (schoolManLic == null) schoolManLic = compLicence; else if (englishLic == null) englishLic = compLicence;
          db.CompanyLicences.Add(compLicence);
        }

        //users
        int lastCounter = 1;
        foreach (var userId in new string[] { "spravce", "ucitel", "student", "ucitelde", "studentde" }) {
          var user = new User() { EMail = userId + "@" + hash + ".cz", Password = "******", FirstName = userId, LastName = "", Created = DateTime.UtcNow, OtherType = (short)OtherType.LANGMaster };
          db.Users.Add(user);
          var compUser = new CompanyUser() { Company = company, User = user, Created = DateTime.UtcNow, CompanyDepartment = dep };
          db.CompanyUsers.Add(compUser);
          if (userId == "spravce") {
            uSpravce = user;
            var courseUser = new CourseUser() { CompanyUser = compUser, Created = DateTime.UtcNow, ProductId = "/lm/blcourse/schoolmanager.product/" };
            db.CourseUsers.Add(courseUser);
            var userLicence = lSpravce = new UserLicence() { CompanyLicence = schoolManLic, CourseUser = courseUser, Started = DateTime.UtcNow, Created = DateTime.UtcNow, Counter = lastCounter++ };
            db.UserLicences.Add(userLicence);
          } else {
            var courseId = userId == "ucitel" || userId == "student" ? "english" : "german";
            var courseUser = new CourseUser() { CompanyUser = compUser, Created = DateTime.UtcNow, ProductId = "/lm/prods_lm_blcourse_" + courseId + "/" };
            db.CourseUsers.Add(courseUser);
            var userLicence = new UserLicence() { CompanyLicence = englishLic, CourseUser = courseUser, Started = DateTime.UtcNow, Created = DateTime.UtcNow, Counter = lastCounter++ };
            db.UserLicences.Add(userLicence);
            switch (userId) {
              case "ucitel": lUcitel = userLicence; uUcitel = user; break;
              case "student": lStudent = userLicence; ; uStudent = user; break;
              case "ucitelde": lUcitelDe = userLicence; uUcitelDe = user; break;
              case "studentde": lStudentDe = userLicence; ; uStudentDe = user; break;
            }
          }
        }

        db.SaveChanges();
        result.newCompanyId = company.Id;

      } else {
        lSpravce = db.UserLicences.Where(l => l.CourseUser.CompanyUser.Company.ScormHost == host && l.CourseUser.CompanyUser.User.EMail == "spravce@" + hash + ".cz" && l.CourseUser.ProductId == "/lm/blcourse/schoolmanager.product/").First();
        lUcitel = db.UserLicences.Where(l => l.CourseUser.CompanyUser.Company.ScormHost == host && l.CourseUser.CompanyUser.User.EMail == "ucitel@" + hash + ".cz" && l.CourseUser.ProductId == "/lm/prods_lm_blcourse_english/").First();
        lStudent = db.UserLicences.Where(l => l.CourseUser.CompanyUser.Company.ScormHost == host && l.CourseUser.CompanyUser.User.EMail == "student@" + hash + ".cz" && l.CourseUser.ProductId == "/lm/prods_lm_blcourse_english/").First();
        lUcitelDe = db.UserLicences.Where(l => l.CourseUser.CompanyUser.Company.ScormHost == host && l.CourseUser.CompanyUser.User.EMail == "ucitelde@" + hash + ".cz" && l.CourseUser.ProductId == "/lm/prods_lm_blcourse_german/").FirstOrDefault();
        lStudentDe = db.UserLicences.Where(l => l.CourseUser.CompanyUser.Company.ScormHost == host && l.CourseUser.CompanyUser.User.EMail == "studentde@" + hash + ".cz" && l.CourseUser.ProductId == "/lm/prods_lm_blcourse_german/").FirstOrDefault();
      }
      Func<UserLicence, User, userItem> createUserItem = (lic, user) => {
        if (lic == null) return null;
        userItem res = new userItem() { licId = lic.LicenceId, licCounter = lic.Counter };
        if (user != null) { res.email = user.EMail; res.firstName = user.FirstName; res.lastName = user.LastName; res.lmcomId = user.Id; }
        return res;
      };
      var master = PrepareDemoData.createEmptyCompany(companyTitle);
      result.admin = createUserItem(lSpravce, uSpravce);
      result.teacher = createUserItem(lUcitel, uUcitel);
      result.student = createUserItem(lStudent, uStudent);
      result.teacherDe = createUserItem(lUcitelDe, uUcitelDe);
      result.studentDe = createUserItem(lStudentDe, uStudentDe);
      result.masterLicId = master.licId;
      result.masterLLicCounter = master.licCounter;
      return result;
    }
Example #2
0
    //*********************** vytvori skolu a licencni klic k school manager produktu (= ostry klic pro spravce skoly)
    public static ICreateEmptySchoolResult createEmptyCompany(string companyTitle) {
      var db = NewData.Lib.CreateContext();
      long hash = companyTitle.GetHashCode(); var host = "blend." + hash;
      var company = db.Companies.FirstOrDefault(c => c.ScormHost == host);
      CompanyLicence schoolManLic = null;
      if (company == null) {
        //company
        company = new Company() { Title = companyTitle, Created = DateTime.UtcNow, ScormHost = host };
        db.Companies.Add(company);
        var dep = new CompanyDepartment() { Title = company.Title, Company = company };
        db.CompanyDepartments.Add(dep);

        //products
        foreach (var prodId in new string[] { "/lm/blcourse/schoolmanager.product/", "/lm/prods_lm_blcourse_english/", "/lm/prods_lm_blcourse_french/", "/lm/prods_lm_blcourse_german/" }) {
          var compLicence = new CompanyLicence() { Company = company, Days = 1000, ProductId = prodId, Created = DateTime.UtcNow, LastCounter = 2 };
          if (schoolManLic == null) schoolManLic = compLicence;
          db.CompanyLicences.Add(compLicence);
        }
        db.SaveChanges();
      } else {
        schoolManLic = db.CompanyLicences.Where(cl => cl.CompanyId==company.Id && cl.ProductId== "/lm/blcourse/schoolmanager.product/").First();
      }
      return new ICreateEmptySchoolResult() { licId = schoolManLic.Id, licCounter = 1 };
    }
Example #3
0
File: Login.cs Project: PavelPZ/REW
    public static CmdAdjustScormUserResult OnScormLogin(CmdAdjustScormUser par) {
      var db = Lib.CreateContext();
      par.companyHost = par.companyHost.ToLowerInvariant();
      par.login = par.login.ToLowerInvariant();
      var login = par.companyHost + "/" + par.login;

      var usr = db.Users.FirstOrDefault(u => u.Login == login);
      var comp = db.Companies.Where(c => c.ScormHost == par.companyHost).FirstOrDefault();
      CompanyUser compUser = null;
      Logger.Log("CmdAdjustScormUserResult Start");
      if (usr == null) //adjust user
        db.Users.Add(usr = new User() { Created = DateTime.UtcNow, EMail = null, Login = login, FirstName = par.firstName, LastName = par.lastName, LoginEMail = null, OtherId = par.login, OtherType = (short)LMComLib.OtherType.scorm });
      else if (comp != null) //comp a user nejsou null => testGlobalAdmin na compuser
        compUser = db.CompanyUsers.FirstOrDefault(cu => cu.CompanyId == comp.Id && cu.UserId == usr.Id);

      if (comp == null) //adjust company
        db.Companies.Add(comp = new Company() { ScormHost = par.companyHost, Title = par.companyHost, Created = DateTime.UtcNow });

      if (compUser == null) //adjust comp user
        db.CompanyUsers.Add(compUser = new CompanyUser() { User = usr, Created = DateTime.UtcNow, Company = comp });
      else if (par.isNotAttempted) { //compUser existuje a isNotAttempted => vymaz vysledky kurzu
        Logger.Log("prodId={0}, userId={1}", par.productId, compUser.Id);
        //foreach (var modData in db.CourseDatas.Where(cd => cd.CourseUser.ProductId == par.productId && cd.CourseUser.email == compUser.compId)) db.CourseDatas.DeleteObject(modData);
        var crsUser = compUser.CourseUsers.FirstOrDefault(crsUsr => crsUsr.ProductId == par.productId);
        if (crsUser != null) db.CourseUsers.Remove(crsUser);
      }

      Lib.SaveChanges(db);

      CmdAdjustScormUserResult res = new CmdAdjustScormUserResult() {
        Cookie = user2cookie(usr),
        companyId = comp.Id,
      };
      return res;
    }
Example #4
0
 //pilotni provoz pro Skrivanka
 static RpcResponse skrivanekResult(CmdSkrivanek par) {
   var lmcomId = NewData.Login.CreateLmUserStart(par.Cookie, par.password);
   if (lmcomId < 0) return new RpcResponse((int)CmdSkrivanekErrors.userExist, null);
   //adjust Skrivanek company
   var db = Lib.CreateContext();
   var skCompany = db.Companies.FirstOrDefault(c => c.Title == skTitle);
   if (skCompany == null) {
     skCompany = new Company { Title = skTitle, Created = DateTime.UtcNow };
     var usr = db.Users.First(u => u.EMail == "*****@*****.**");
     var dep = new CompanyDepartment() { Title = skCompany.Title, Company = skCompany };
     db.CompanyDepartments.Add(dep);
     var compUser = new CompanyUser() { Company = skCompany, User = usr, Created = DateTime.UtcNow, RolesEx = (long)CompRole.All, CompanyDepartment = dep };
     Lib.SaveChanges(db);
   }
   //adjust Licence
   var prodLicence = AdminServ.adjustAddHocLicence(skCompany.Id, lmcomId, 0, par.productUrl);
   //use licence
   var res = NewData.My.AddLicence(prodLicence.Id, lmcomId, prodLicence.LastCounter);
   if (res.res != EnterLicenceResult.ok) throw new Exception();
   return new RpcResponse(new CmdSkrivanekResult { lmcomId = lmcomId, companyId = skCompany.Id });
 } const string skTitle = "Skřivánek - pilotní provoz";
Example #5
0
File: Admin.cs Project: 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;
 }