public PartialViewResult RemoveEducation(int id)
 {
     var edu = new Models.Education() { ID = id };
     var tblEdu = new TblEducation();
     tblEdu.Delete(edu);
     return PartialView("_PartialEducation", tblEdu.GetAll());
 }
 public PartialViewResult UpdateEducation(Models.Education e)
 {
     var edu = new Models.Education() { ID = e.ID, University = HttpUtility.UrlDecode(e.University), Faculty = HttpUtility.UrlDecode(e.Faculty), Department = HttpUtility.UrlDecode(e.Department), Date = HttpUtility.UrlDecode(e.Date) };
     var tblEdu = new TblEducation();
     tblEdu.Update(edu);
     return PartialView("_PartialEducation", tblEdu.GetAll());
 }
示例#3
0
        public ActionResult DeleteConfirmed(Guid id, List <Guid> ids)
        {
            if (Session["Login"] == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            foreach (var eduid in ids)
            {
                Models.Education edu = db.Educations.Find(eduid);
                db.Educations.Remove(edu);
                db.SaveChanges();
            }

            //foreach (var eduEdit in employeeViewModel.Educations)
            //{
            //    Models.Education edus = db.Educations.Find(Guid.Parse(eduEdit.EducationId));
            //    var schoolname = eduEdit.SchoolName;
            //    var department = eduEdit.Department;
            //    var dgreee = eduEdit.Drgree;
            //    var sdate = eduEdit.StartDate;
            //    var enddate = eduEdit.EndDate;

            //    //Models.Education eduss = new Models.Education();
            //    //edus.EducationId = Guid.NewGuid();
            //    //edus.SchoolName = schoolname;
            //    //edus.Department = department;
            //    //edus.Degree = dgreee;
            //    //edus.StartDate = DateTime.Parse(sdate);
            //    //edus.EndDate = DateTime.Parse(enddate);
            //    //edus.EmployeeId = employee.EmployeeId;
            //    //db.Educations.Add(edus);
            //    db.Educations.Remove(edus);
            //    db.SaveChanges();

            //}
            Employee employee = db.Employees.Find(id);

            db.Employees.Remove(employee);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#4
0
        public ActionResult Create(EmployeeViewModel employeeViewModel,
                                   HttpPostedFileBase PhotoPath)
        {
            //if (Session["Login"] == null)
            //{
            //    return RedirectToAction("Index", "Login");
            //}
            if (ModelState.IsValid)
            {
                string strPath     = "";
                string newfilename = "";
                if (PhotoPath != null)
                {
                    int    startindex = PhotoPath.ContentType.LastIndexOf('/') + 1;
                    string filetype   = PhotoPath.ContentType.Substring(startindex); //取得副檔名
                    newfilename = Guid.NewGuid() + "." + filetype;
                    strPath     = Request.PhysicalApplicationPath + @"images\Employees\" + newfilename;
                    PhotoPath.SaveAs(strPath);
                }

                // Address
                Address address = new Address();
                address.AddressId   = Guid.NewGuid();
                address.CityId      = Guid.Parse(employeeViewModel.CitySelectedValue);
                address.DistrictId  = Guid.Parse(employeeViewModel.DistrictSelectedValue);
                address.AddressLine = employeeViewModel.AddressLine;
                db.Addresses.Add(address);
                db.SaveChanges();
                //Residential Address
                Address ResidentialAddress = new Address();
                ResidentialAddress.AddressId   = Guid.NewGuid();
                ResidentialAddress.CityId      = Guid.Parse(employeeViewModel.ResidentialCitySelectedValue);
                ResidentialAddress.DistrictId  = Guid.Parse(employeeViewModel.ResidentialDistrictSelectedValue);
                ResidentialAddress.AddressLine = employeeViewModel.ResidentialAddressLine;
                db.Addresses.Add(ResidentialAddress);
                db.SaveChanges();
                //Employee
                Employee emp = new Employee();
                emp.EmployeeId           = Guid.NewGuid();
                emp.EmployeeName         = employeeViewModel.EmployeeName;
                emp.EmployeeNameEn       = employeeViewModel.EmployeeNameEn;
                emp.BirthDate            = employeeViewModel.BirthDate;
                emp.IdCardNum            = employeeViewModel.IdCardNum;
                emp.Gender               = (int)employeeViewModel.Gender == 1;
                emp.BloodType            = employeeViewModel.BloodType;
                emp.MobilePhone          = employeeViewModel.MobilePhone;
                emp.PermanentAddressId   = address.AddressId;
                emp.ResidentialAddressId = ResidentialAddress.AddressId;
                emp.Email              = employeeViewModel.Email;
                emp.PermanentTel       = employeeViewModel.PermanentTel;
                emp.ResidentialTel     = employeeViewModel.ResidentialTel;
                emp.PhotoPath          = newfilename;
                emp.OnBoardDate        = employeeViewModel.OnBoardDate;
                emp.EmpId              = employeeViewModel.EmpId;
                emp.IsMarried          = (int)employeeViewModel.IsMarried == 1;
                emp.CreateOn           = DateTime.Now;
                emp.HasChild           = (int)employeeViewModel.HasChild == 1;
                emp.ModifiedOn         = DateTime.Now;
                emp.EmployeeStatusesId = db.EmployeeStatuses.Single(x => x.Name == "Active").EmployeeStatusId;
                emp.IsDisability       = (int)employeeViewModel.IsDisability == 1;
                emp.IsAboriginal       = (int)employeeViewModel.IsAboriginal == 1;
                db.Employees.Add(emp);
                db.SaveChanges();

                //Education
                //var q = new List<ViewModel.Education>();
                foreach (var edu in employeeViewModel.Educations)
                {
                    var schoolname = edu.SchoolName;
                    var department = edu.Department;
                    var dgreee     = edu.Drgree;
                    var sdate      = edu.StartDate;
                    var enddate    = edu.EndDate;

                    Models.Education edus = new Models.Education();
                    edus.EducationId = Guid.NewGuid();
                    edus.SchoolName  = schoolname;
                    edus.Department  = department;
                    edus.Degree      = dgreee;
                    edus.StartDate   = DateTime.Parse(sdate);
                    edus.EndDate     = DateTime.Parse(enddate);
                    edus.EmployeeId  = emp.EmployeeId;
                    db.Educations.Add(edus);
                    db.SaveChanges();
                }

                //emp.Educations.Where(x=>x.EducationId) = Guid.NewGuid();

                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("Create"));
        }