private static string InsertCompanyEmployee(CompanyEmployeeServices service)
        {
            CompanyDepartmentServices departmentService = new CompanyDepartmentServices();
            List <CompanyDepartment>  departments       = departmentService.GetAllDepartments();
            CompanyDepartment         department        = departments.Find(x => x.maxEmployees == 1);
            CompanyEmployee           employee          = new CompanyEmployee()
            {
                firstName            = "John",
                lastName             = "Black",
                birthDate            = DateTime.Now,
                emailAddress         = "*****@*****.**",
                CompanyDepartment_ID = department.ID,
                companyDepartment    = department
            };
            string          result    = service.InsertNewEmployee(employee);
            CompanyEmployee employee2 = new CompanyEmployee()
            {
                firstName            = "George",
                lastName             = "Blue",
                birthDate            = DateTime.Now,
                emailAddress         = "*****@*****.**",
                CompanyDepartment_ID = departments.Find(x => x.CurrentEmployees < x.maxEmployees).ID,
                companyDepartment    = departments.Find(x => x.CurrentEmployees < x.maxEmployees)
            };

            result = result + " " + service.InsertNewEmployee(employee2);
            return(result);
        }
Example #2
0
 public string InsertNewDepartment(CompanyDepartment department)
 {
     department.CurrentEmployees = 0;
     departmentRepo.Add(department);
     departmentRepo.Save();
     return("New department added");
 }
Example #3
0
 protected void btnDepartment_Click(object sender, EventArgs e)
 {
     //this sets all buttons to secondary and makes this one primary to show its selected.
     Session["tab"] = "dept";
     clearButtons();
     btnDepartment.CssClass  = "tabSelected leftMenuButton";
     accordContent.InnerHtml = CompanyDepartment.getDepartmentsForLeftMenu();
 }
Example #4
0
 public Employee(string Name, double Salary, CompanyPositions Position, CompanyDepartment Department, string Email = "", int Age = -1)
 {
     this.Name       = Name;
     this.Salary     = Salary;
     this.Position   = Position;
     this.Department = Department;
     this.Email      = Email;
     this.Age        = Age;
 }
    public static string getDepartmentsForLeftMenu()
    {
        DataTable departments = SystemMethods.getDataTableFromStoredProcedure("stpGetDepartments");
        string    letters     = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        int       rows        = departments.Rows.Count;
        string    html        = "";
        List <CompanyDepartment> departmentList = new List <CompanyDepartment>();

        for (int uth = 0; uth < rows; uth++)
        {
            departmentList.Add(new CompanyDepartment(Int32.Parse(departments.Rows[uth]["departmentId"].ToString()), departments.Rows[uth]["departmentName"].ToString()));
        }
        //this for loop sorts the departments and makes html ready to go.
        for (int uth = 0; uth < letters.Length; uth++)
        {
            //make header is the make the clickable letter. you only want it once
            int makeHeader = 1;
            //while true because there could be 0-9000 departments with the same letter
            while (true)
            {
                //this finds a department in the list.
                //letters is a string with A-Z.
                //we need to sort the dept list alphabetically first here i think? - SH
                CompanyDepartment foundDepartment = departmentList.Find(x => x.firstLetter == letters[uth]);
                //if foundDepartment is null that mena no match.
                if (foundDepartment == null)
                {
                    //no match means no more in that letter.
                    break;
                }
                //this should only happen once per found letter.
                if (makeHeader == 1)
                {
                    //makes the clickable "link"
                    html += "<div id='" + letters[uth] + "'>";
                    html += "<h2><a href='#" + letters[uth] + "'>" + letters[uth] + "</a></h2>";
                    //gets marked to 0 because this letter was just made.
                    makeHeader = 0;
                }
                //removes the foundDepartment from the list.
                departmentList.Remove(foundDepartment);
                //finally this is the link inside a clickable letter.

                //change localhost when put on azure
                html += "<p><a href='/FunctionListing/" + foundDepartment.departmentId + "#" + letters[uth] + "'>" + foundDepartment.departmentName + "</a></p>";
            }
            //this is in case a letter was not found it skips this.
            //it is to close the div made to be clicked.
            if (makeHeader == 0)
            {
                html += "</div>";
            }
        }
        //returns this html back.
        return(html);
    }
        private static string InsertCompanyDepartment(CompanyDepartmentServices service)
        {
            CompanyDepartment department = new CompanyDepartment()
            {
                Name         = "HR",
                maxEmployees = 1
            };

            return(service.InsertNewDepartment(department));
        }
Example #7
0
 public string EditExistingDepartment(CompanyDepartment department)
 {
     if (department.maxEmployees < department.CurrentEmployees)
     {
         throw new Exception(string.Format(Messages.sCurrentGreaterThanMax, department.CurrentEmployees, department.maxEmployees));
     }
     departmentRepo.Update(department);
     departmentRepo.Save();
     return("Department updated");
 }
Example #8
0
 public JsonResult EditDepartment(CompanyDepartment department)
 {
     try
     {
         return(Json(departmentService.EditExistingDepartment(department)));
     }
     catch (Exception ex)
     {
         return(Json(ex.Message));
     }
 }
        private static string updateFirstDepartment(CompanyDepartmentServices service, List <CompanyDepartment> departments)
        {
            CompanyDepartment department = departments.FirstOrDefault();

            if (department != null)
            {
                department.Name         = "Logistics";
                department.maxEmployees = 3;
            }
            return(service.EditExistingDepartment(department));
        }
Example #10
0
 public JsonResult CreateDepartment(CompanyDepartment department)
 {
     try
     {
         return(Json(departmentService.InsertNewDepartment(department)));
     }
     catch (Exception ex)
     {
         return(Json(ex.Message));
     }
 }
Example #11
0
 // GET: Department/Create
 public ActionResult Create()
 {
     try
     {
         CompanyDepartment department = new CompanyDepartment();
         return(View(department));
     }
     catch (Exception ex)
     {
         return(ShowExceptionMessage(ex));
     }
 }
        //protected override void LoadAllCommandCompletedHelper()
        //{
        //    try
        //    {
        //        dispatcher.BeginInvoke
        //                   (() =>
        //                   {
        //                       if (Utility.FaultExist(companyDepartmentJobRoleService.Fault))
        //                       {
        //                           return;
        //                       }

        //                       Models = new PagedCollectionView(companyDepartmentJobRoleService.Models);
        //                       if (companyDepartmentJobRoleService.Models != null && companyDepartmentJobRoleService.Models.Count > 0)
        //                       {
        //                           RecordCount = RecordCountLabel + companyDepartmentJobRoleService.Models.Count;
        //                           Models.MoveCurrentTo(null);
        //                           Models.CurrentChanged += (s, e) =>
        //                           {
        //                               SetSelectedModel();
        //                           };
        //                       }
        //                       else
        //                       {
        //                           RecordCount = RecordCountLabel + 0;
        //                       }
        //                   });
        //    }
        //    catch (Exception ex)
        //    {
        //        Utility.DisplayMessage(ex.Message);
        //    }
        //}


        protected override void SetSelectedModel()
        {
            try
            {
                if (Models != null)
                {
                    Model = Models.CurrentItem as CompanyDepartmentJobRole;

                    if (Model != null)
                    {
                        //if (Companies != null)
                        //{
                        //    ObservableCollection<Company> companies = (ObservableCollection<Company>)Companies.SourceCollection;
                        //    Company company = companies.Where(c => c.Id == Model.Company.Id).SingleOrDefault();
                        //    if (company != null)
                        //    {
                        //        Companies.MoveCurrentTo(company);
                        //    }
                        //}

                        if (CompanyDepartments != null)
                        {
                            ObservableCollection <CompanyDepartment> departments = (ObservableCollection <CompanyDepartment>)CompanyDepartments.SourceCollection;
                            CompanyDepartment department = departments.Where(d => d.Department.Id == Model.Department.Id && d.Company.Id == Model.Company.Id).SingleOrDefault();
                            if (department != null)
                            {
                                CompanyDepartments.MoveCurrentTo(department);
                            }
                        }

                        if (JobRoles != null)
                        {
                            ObservableCollection <JobRole> jobRoles = (ObservableCollection <JobRole>)JobRoles.SourceCollection;
                            JobRole jobRole = jobRoles.Where(d => d.Id == Model.JobRole.Id).SingleOrDefault();
                            if (jobRole != null)
                            {
                                JobRoles.MoveCurrentTo(jobRole);
                            }
                        }
                    }

                    UpdateViewState(Edit.Mode.Editing);
                }
            }
            catch (Exception ex)
            {
                Utility.DisplayMessage(ex.Message);
            }
        }
Example #13
0
        private static string updateFirstEmployee(CompanyEmployeeServices service, List <CompanyEmployee> employees)
        {
            CompanyDepartmentServices departmentService = new CompanyDepartmentServices();
            List <CompanyDepartment>  departments       = departmentService.GetAllDepartments();
            CompanyDepartment         department        = departments.Find(x => x.Name == "Logistics");
            CompanyEmployee           employee          = employees.Find(x => x.firstName == "John");

            if (employee != null)
            {
                employee.firstName            = "Jonathan";
                employee.CompanyDepartment_ID = department.ID;
                employee.companyDepartment    = department;
            }
            return(service.EditExistingEmployee(employee));
        }
Example #14
0
        public string DeleteDepartment(CompanyDepartment department)
        {
            string result = string.Empty;

            if (!DepartmentHasEmployees(department))
            {
                departmentRepo.Delete(department);
                departmentRepo.Save();
                result = "Department has been deleted";
            }
            else
            {
                throw new Exception(string.Format(Messages.sNotEmptyDepartment, department.CurrentEmployees));
            }
            return(result);
        }
Example #15
0
        public IActionResult AddDepartment(int?Id, CompanyDepartment CompanyDepartment)
        {
            if (Id.HasValue)
            {
                var companies = context.Companies
                                .Where(x => x.HoldingId == Id.Value)
                                .Select(x => new SelectListItem {
                    Text = x.Name, Value = x.Id.ToString()
                });

                return(PartialView("CompanySelect", companies));
            }

            context.CompanyDepartments.Add(CompanyDepartment);
            context.SaveChanges();

            return(RedirectToAction("AddDepartment", "Admin"));
        }
Example #16
0
 public ActionResult Edit(CompanyDepartment department)
 {
     try
     {
         if (ModelState.IsValid)
         {
             string result = departmentService.EditExistingDepartment(department);
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View(department));
         }
     }
     catch (Exception ex)
     {
         return(ShowExceptionMessage(ex));
     }
 }
Example #17
0
 // POST: Department/Create
 public ActionResult Create(CompanyDepartment department)
 {
     try
     {
         if (ModelState.IsValid)
         {
             departmentService.InsertNewDepartment(department);
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View());
         }
     }
     catch (Exception ex)
     {
         return(ShowExceptionMessage(ex));
     }
 }
        protected void LoadAllCompanyDepartmentsByCompanyCompletedHelper()
        {
            try
            {
                dispatcher.BeginInvoke
                    (() =>
                {
                    if (Utility.FaultExist(companyDepartmentService.Fault))
                    {
                        return;
                    }

                    if (companyDepartmentService.CompanyDepartments != null && companyDepartmentService.CompanyDepartments.Count > 0)
                    {
                        companyDepartmentService.CompanyDepartments.Insert(0, new CompanyDepartment()
                        {
                            Department = new Department()
                            {
                                Id = "0", Name = "<< Select Department >>"
                            }
                        });

                        CompanyDepartments = new PagedCollectionView(companyDepartmentService.CompanyDepartments);
                        CompanyDepartments.MoveCurrentToFirst();
                        CompanyDepartments.CurrentChanged += (s, e) =>
                        {
                            CompanyDepartment = CompanyDepartments.CurrentItem as CompanyDepartment;
                        };
                    }
                });
            }
            catch (Exception ex)
            {
                Utility.DisplayMessage(ex.Message);
            }
        }
 public async Task <bool> CreateCompanyDepartment(CompanyDepartment model) => await _service.Add(model);
Example #20
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 #21
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 #22
0
 private bool DepartmentHasEmployees(CompanyDepartment department)
 {
     return(department.CurrentEmployees > 0);
 }
Example #23
0
        public string DeleteDepartmentByID(System.Guid departmentID)
        {
            CompanyDepartment department = departmentRepo.GetById(departmentID);

            return(DeleteDepartment(department));
        }
Example #24
0
        private static string DeleteLastDepartment(CompanyDepartmentServices service, List <CompanyDepartment> departments)
        {
            CompanyDepartment department = departments.LastOrDefault();

            return(service.DeleteDepartment(department));
        }
Example #25
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var randomSalary = new Random();
            var dev1         = new Developer("Lucas", GetRamdomSalary(randomSalary), new List <string> {
                "skill1", "skill2", "skill3", "skill4"
            });
            var dev2 = new Developer("Bruno", GetRamdomSalary(randomSalary), new List <string> {
                "skill1", "skill2", "skill3"
            });
            var dev3 = new Developer("Maria", GetRamdomSalary(randomSalary), new List <string> {
                "skill1", "skill2"
            });

            var qa1 = new Developer("Julia", GetRamdomSalary(randomSalary), new List <string> {
                "skill1", "skill2", "skill3", "skill4"
            });
            var qa2 = new Developer("Pedro", GetRamdomSalary(randomSalary), new List <string> {
                "skill1", "skill2", "skill3"
            });
            var qa3 = new Developer("Lucia", GetRamdomSalary(randomSalary), new List <string> {
                "skill1", "skill2"
            });
            var qa4 = new Developer("Roberto", GetRamdomSalary(randomSalary), new List <string> {
                "skill1", "skill2", "skill5"
            });

            var sectorDev = new CompanySector("Desenvolvimento");

            sectorDev.AddMember(dev1);
            sectorDev.AddMember(dev2);
            sectorDev.AddMember(dev3);

            var sectorQA = new CompanySector("Qualidade");

            sectorQA.AddMember(qa1);
            sectorQA.AddMember(qa2);
            sectorQA.AddMember(qa3);
            sectorQA.AddMember(qa4);

            var tiDepartment     = new CompanyDepartment("Tecnologia da Informação");
            var developerManager = new Manager("Adriana", GetRamdomSalary(randomSalary), "Gerente de Desenvolvimento");

            tiDepartment.AddMember(developerManager);
            tiDepartment.AddMember(sectorDev);

            var qualityAnalystManager = new Manager("Pedro", GetRamdomSalary(randomSalary), "Gerente de Qualidade");

            tiDepartment.AddMember(qualityAnalystManager);
            tiDepartment.AddMember(sectorQA);

            var rhManager    = new Manager("Luisa", GetRamdomSalary(randomSalary), "Gerente de RH");
            var rhDepartment = new CompanyDepartment("Recursos Humanos");

            rhDepartment.AddMember(rhManager);

            var director     = new Director("Nathália", GetRamdomSalary(randomSalary), "Dona da Empresa");
            var headQuarters = new CompanyHeadquarters("Matriz");

            headQuarters.AddMember(director);
            headQuarters.AddRangeMember(new List <CompanyMember> {
                rhDepartment, tiDepartment
            });

            Console.WriteLine($"Salario total: {headQuarters.GetSalary()}");
            headQuarters.Show();
            Console.ReadKey();
        }
Example #26
0
        public static void ITCompany()
        {
            String op = "";

            List <Employee> list = new List <Employee>();

            while (op != "q")
            {
                Console.Write("Enter employee name:");
                string name = Console.ReadLine();

                Console.Write("Enter employee salary:");
                double salary;
                Double.TryParse(Console.ReadLine(), out salary);

                Console.Write("Enter employee position:");
                foreach (var item in Enum.GetValues(typeof(CompanyPositions)))
                {
                    Console.WriteLine($"{(int)item} for {item}");
                }
                int pos;
                Int32.TryParse(Console.ReadLine(), out pos);


                Console.Write("Enter employee department:");
                foreach (var item in Enum.GetValues(typeof(CompanyDepartment)))
                {
                    Console.WriteLine($"{(int)item} for {item}");
                }
                int dep;
                Int32.TryParse(Console.ReadLine(), out dep);

                Console.Write("Enter employee email:");
                string email = Console.ReadLine();

                Console.Write("Enter you age:");
                int age = -1;
                Int32.TryParse(Console.ReadLine(), out age);

                list.Add(new Employee(name, salary, (CompanyPositions)pos, (CompanyDepartment)dep, email, age));

                Console.WriteLine("\"Enter\" for More \"q\" for end");
                op = Console.ReadLine();
            }

            //list.Sort(PersonCompare); //-->with method
            //list.Sort( delegate (Person a, Person b) { return a.Name.CompareTo(b.Name); }); //--> with anonymous method
            //list.Sort((a, b) => { return a.Name.CompareTo(b.Name); }); //-->witn Lambda Expression

            /*
             * list.Sort((a, b) => {
             *  int res = a.Name.CompareTo(b.Name);
             *  if (res != 0)
             *      return res;
             *  else
             *      return a.Age.CompareTo(b.Age);
             * }); //-->wit Lambda Expression compare both fields
             */
            SortedList <CompanyDepartment, Double> sl = new SortedList <CompanyDepartment, Double>();

            CompanyDepartment cd  = CompanyDepartment.DEVELOPMENT;
            Double            max = 0d;
            int counter           = 0;

            foreach (CompanyDepartment item in Enum.GetValues(typeof(CompanyDepartment)))
            {
                counter = 0;
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].Department == item)
                    {
                        if (sl.ContainsKey(item))
                        {
                            sl[item] += list[i].Salary;
                        }
                        else
                        {
                            sl.Add(item, list[i].Salary);
                        }
                        counter++;
                    }
                }


                if (sl.ContainsKey(item))
                {
                    //calculating average
                    sl[item] = sl[item] / counter;

                    //getting max average and department
                    if (sl[item] > max)
                    {
                        max = sl[item];
                        cd  = item;
                    }
                }
            }

            foreach (var item in list)
            {
                if (item.Department == cd)
                {
                    Console.WriteLine(item);
                }
            }
        }
Example #27
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 #28
0
File: Admin.cs Project: PavelPZ/REW
 //static CmdGetDepartmentResult GetDepartment(CmdGetDepartment par) {
 //  var db = lib.CreateContext();
 //  var allDeps = db.CompanyDepartments.Where(d => d.CompanyId == par.CompanyId).ToArray();
 //  var allUsed = db.CompanyUsers.Where(d => d.CompanyId == par.CompanyId && d.DepartmentId != null).Select(u => u.DepartmentId).Distinct().ToArray();
 //  return new CmdGetDepartmentResult() {
 //    Departments = GetDepartment (allDeps),
 //    UsedIds = allUsed.OfType<int>().ToArray()
 //  };
 //}
 static Department GetDepartment(CompanyDepartment[] allDb, CompanyDepartment actDb = null) {
   if (allDb == null || allDb.Length == 0) return null;
   if (actDb == null) actDb = allDb.First(d => d.ParentId == null);
   return new Department() {
     Id = actDb.Id,
     Title = actDb.Title,
     Items = allDb.Where(d => d.ParentId == actDb.Id).Select(d => GetDepartment(allDb, d)).ToArray()
   };
 }
Example #29
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //this defaults to false because we should assume people are not allowed in.
        btnAdmin.Visible = false;
        try
        {
            //this makes sure the ticket they have is vaild
            if (!Request.IsAuthenticated)
            {
                //if ticket not vaild goto login.
                Response.Redirect("~/login.aspx");
            }
            //this decrpyts the ticket in order to retrive the userId and Role.
            FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Request.Cookies["mysite.ASPXAUTH"].Value);
            //this makes sure the user is still allowed on the website.
            if (!SystemUser.userVaildCheck(Int32.Parse(ticket.Name), Session["key"].ToString()))
            {
                //if not allowed goto login.
                Response.Redirect("~/login.aspx");
            }
            //this gets the user role out of ticket.
            int userRole = Int32.Parse(ticket.UserData);
            //check to see if admin tab should be shown
            if (userRole == 1 || userRole == 4)
            {
                //shows tab
                btnAdmin.Visible = true;
            }
            //puts the persons name on screen...makes them feel like a person....not a number i guess.
            menuPersonName.InnerText = Request.Cookies["name"].Value;
        }
        catch (Exception ex)
        {
            //if anything goes wrong here i assume they are not allowed and force them to login.
            Response.Redirect("~/login.aspx");
        }
        clearButtons();
        //this bit of code. gets the session that remembers what tab you were on between pages.
        //its almost like we care about people...
        //the only 3 options for this
        // dept
        // staff
        // admin
        switch (Session["tab"].ToString())
        {
        case "dept":
            btnDepartment.CssClass  = "tabSelected leftMenuButton";
            accordContent.InnerHtml = CompanyDepartment.getDepartmentsForLeftMenu();
            break;

        case "staff":
            btnStaff.CssClass       = "tabSelected leftMenuButton leftMenuButtonMoveLeft";
            accordContent.InnerHtml = CompanyStaffMember.getStaffMembersForLeftMenu();
            break;

        case "admin":
            btnAdmin.CssClass       = "tabSelected leftMenuButton leftMenuButtonMoveLeft";
            accordContent.InnerHtml = SystemMethods.adminLeftMenu();
            break;
        }
    }
Example #30
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;
 }