Beispiel #1
0
        public void Update(int id, CompanyModel comp)
        {
            using (pumoxEntities ent = new pumoxEntities())
            {
                var c = ent.Company.Where(x => x.Id == id).SingleOrDefault();
                c.Name = comp.Name;
                c.EstabilishmentYear = comp.EstabilishmentYear;

                var query = ent.Employee.Where(x => x.CompanyId == id).ToList();
                foreach (var item in query)
                {
                    ent.Employee.Remove(item);
                }

                foreach (var item in comp.Employees)
                {
                    Employee emp = new Employee();

                    emp.Company     = c;
                    emp.Firstname   = item.FirstName;
                    emp.Lastname    = item.LastName;
                    emp.DateOfBirth = item.DateOfBirth;
                    emp.JobTitle    = (int?)item.JobTitle;

                    ent.Employee.Add(emp);
                }

                ent.SaveChanges();
            }
        }
Beispiel #2
0
 public void Delete(int id)
 {
     using (pumoxEntities ent = new pumoxEntities())
     {
         var employees = ent.Employee.Where(x => x.CompanyId == id);
         foreach (var item in employees)
         {
             ent.Employee.Remove(item);
         }
         var company = ent.Company.SingleOrDefault(x => x.Id == id);
         ent.Company.Remove(company);
     }
 }
Beispiel #3
0
        public IEnumerable <Employee> Search(string keyword, DateTime?employeeDateOfBirthFrom, DateTime?employeeDateOfBirthTo, JobTitles employeeJobTitles)
        {
            pumoxEntities ent = new pumoxEntities();

            ent.Configuration.ProxyCreationEnabled = false;
            var res = FilterByKeword(ent.Employee, keyword);

            res = FilterByDate(res, employeeDateOfBirthFrom, employeeDateOfBirthTo);
            res = FilterByJobTitle(res, employeeJobTitles);



            //var result = res.GroupBy(x => new { x.Company.Name, x.Company.EstabilishmentYear }).ToList();

            //return result;
            return(res);
        }
Beispiel #4
0
        // POST company/create
        public long Create(CompanyModel comp)
        {
            using (pumoxEntities ent = new pumoxEntities())
            {
                var c = new Company();
                c.Name = comp.Name;
                c.EstabilishmentYear = comp.EstabilishmentYear;
                comp.Employees       = comp.Employees ?? new List <EmployeeModel>();
                foreach (var item in comp.Employees)
                {
                    var emp = new Employee();
                    emp.Company     = c;
                    emp.Firstname   = item.FirstName;
                    emp.Lastname    = item.LastName;
                    emp.DateOfBirth = item.DateOfBirth;
                    emp.JobTitle    = (int?)item.JobTitle;

                    ent.Employee.Add(emp);
                }
                ent.Company.Add(c);
                ent.SaveChanges();
                return(c.Id);
            }
        }