Пример #1
0
        //Update Employee
        public ActionResult UpdateEmployee(EmployeeViewModel newEmployeeData)
        {
            Department department = departmentService.GetDepartmentByName(newEmployeeData.Department);

            Employee Employee = new Employee()
            {
                EmployeeID   = newEmployeeData.EmployeeID,
                FirstName    = newEmployeeData.FirstName,
                MiddleName   = newEmployeeData.MiddleName,
                LastName     = newEmployeeData.LastName,
                DepartmentID = department.DepartmentID,
                InsertedDate = DateTime.Now
            };

            EmployeePersonalInfo EmployeePersonalInfo = new EmployeePersonalInfo()
            {
                EmployeeID = newEmployeeData.EmployeeID,
                Phone      = newEmployeeData.Phone,
                Address    = newEmployeeData.Address,
                Position   = newEmployeeData.Position,
                Gender     = newEmployeeData.Gender,
                HiredDate  = newEmployeeData.HiredDate,
                //ResignationDate = newEmployeeData.ResignationDate,
                InsertedDate = DateTime.Now
            };

            employeeService.UpdateEmployee(Employee);
            return(RedirectToAction("Index"));
        }
Пример #2
0
        public ActionResult SaveEmployee(EmployeeViewModel employeeData)
        {
            Department department = departmentService.GetDepartmentByName(employeeData.Department);

            EmployeePersonalInfo employeePersonalInfo = new EmployeePersonalInfo()
            {
                Phone     = employeeData.Phone,
                Address   = employeeData.Address,
                Position  = employeeData.Position,
                Gender    = employeeData.Gender,
                HiredDate = employeeData.HiredDate,
                //ResignationDate = employeeData.ResignationDate,
                InsertedDate = DateTime.Now
            };

            ;
            Employee Employee = new Employee()
            {
                FirstName            = employeeData.FirstName,
                MiddleName           = employeeData.MiddleName,
                LastName             = employeeData.LastName,
                InsertedDate         = DateTime.Now,
                DepartmentID         = department.DepartmentID,
                Email                = employeeData.Email,
                EmployeePersonalInfo = employeePersonalInfo
            };

            employeeService.SaveEmployee(Employee);
            return(View(employeeData));
        }
Пример #3
0
 //Delete EmployeePersonalInfo
 public void RemoveEmployee(EmployeePersonalInfo employeePersonalInfoToBeDeleted)
 {
     using (var dataContext = new DataContext())
     {
         dataContext.Entry(employeePersonalInfoToBeDeleted).State = EntityState.Deleted;
         dataContext.SaveChanges();
     }
 }
Пример #4
0
 //Read EmployeePersonalInfo
 public EmployeePersonalInfo GetEmployeePersonalInfoByID(int empId)
 {
     using (var dataContext = new DataContext())
     {
         EmployeePersonalInfo EmployeePersonalInfo = (from employeePersonalInfo in dataContext.employeePersonalInfo
                                                      where employeePersonalInfo.EmployeeID == empId
                                                      select employeePersonalInfo).First();
         return(EmployeePersonalInfo);
     }
 }
Пример #5
0
 public void InsertOrUpdate(EmployeePersonalInfo personalInfo)
 {
     if (_context.EmployeePersonalInfos.Find(personalInfo.Id) == null)
     {
         // New entity
         _context.Entry(personalInfo).State = EntityState.Added;
     }
     else
     {
         // Existing entity
         _context.Entry(personalInfo).State = EntityState.Modified;
     }
 }
        public string DispatchCommand(string[] command)
        {
            if (command[0].ToLower() == "addemployee" && command.Length == 4)
            {
                return(AddEmployee.Execute(command));
            }

            if (command[0].ToLower() == "setbirthday" && command.Length == 4)
            {
                return(SetBirthday.Execute(command));
            }

            if (command[0].ToLower() == "setaddress" && command.Length >= 3 && char.IsNumber(command[1], 0))
            {
                return(SetAddress.Execute(command));
            }

            if (command[0].ToLower() == "employeeinfo" && command.Length == 2)
            {
                return(EmployeeInfo.Execute(command));
            }

            if (command[0].ToLower() == "employeepersonalinfo" && command.Length == 2)
            {
                return(EmployeePersonalInfo.Execute(command));
            }

            if (command[0].ToLower() == "exit" && command.Length == 1)
            {
                return(Exit.Execute(command));
            }

            if (command[0].ToLower() == "setmanager" && command.Length == 3)
            {
                return(SetManager.Execute(command));
            }

            if (command[0].ToLower() == "managerinfo" && command.Length == 2)
            {
                return(ManagerInfo.Execute(command));
            }

            if (command[0].ToLower() == "listemployeesolderthan" && command.Length == 2)
            {
                return(ListEmployeesOlderThan.Execute(command));
            }

            return("Invalid Command");
        }
Пример #7
0
        public void CheckIfEmployeePersonalDetailsIsSaved()
        {
            // ARRANGE
            var uow = Mock.Create <IQTecUnitOfWork>(Behavior.Loose);

            var employeeToBeUpdated = new Employee
            {
                DateOfBirth   = new DateTime(2012, 1, 1),
                DesignationId = 2,
                Email         = "*****@*****.**",
                FirstName     = "Abc",
                LastName      = "XYZ"
            };

            var employeePersonalDtoinParamater = new EmployeePersonalInfo
            {
                DateOfBirth   = new DateTime(2012, 1, 1),
                DesignationId = 2,
                Email         = "*****@*****.**",
                FirstName     = "AbcDef",                                 //firstname is changed
                LastName      = "XYZ"
            };

            Mock.Arrange(() => uow.EmployeeRepository.GetById(Arg.AnyInt)).Returns(employeeToBeUpdated);

            Mock.Arrange(() => uow.EmployeeRepository.Update(Arg.IsAny <Employee>()))
            .DoInstead(() => { employeeToBeUpdated.FirstName = employeePersonalDtoinParamater.FirstName; })
            .OccursOnce();

            Mock.Arrange(() => uow.EmployeeLanguagesRepository.GetAll()).DoNothing();

            // ACT
            var classunderTest = new EmployeeManager(uow);

            classunderTest.SaveEmployee(1, employeePersonalDtoinParamater, null);


            // ASSERT
            Assert.AreEqual("AbcDef", employeeToBeUpdated.FirstName);
            Mock.Assert(uow);
        }
Пример #8
0
        private EmployeeHeader PrepareEmployeeHeader(EmployeeHeader employeeHeader, HttpFileCollection hfc = null, List <EmployeeDocumentViewModel> employeeDocumentViewModel = null)
        {
            EmployeeHeader _employeeHeader = null;

            if (employeeHeader.Id > 0)
            {
                _employeeHeader            = EmployeeProfileService.GetEmployeeProfileDetailsById(employeeHeader.Id);
                _employeeHeader.ModifiedBy = USER_OBJECT.UserName;
                _employeeHeader.ModifiedOn = DateTimeConverter.SingaporeDateTimeConversion(DateTime.Now);
            }
            else
            {
                _employeeHeader           = new EmployeeHeader();
                _employeeHeader.CreatedBy = USER_OBJECT.UserName;
                _employeeHeader.CreatedOn = DateTimeConverter.SingaporeDateTimeConversion(DateTime.Now);
            }
            EmployeePersonalInfo employeePersonalInfo = employeeHeader.EmployeePersonalInfo.FirstOrDefault();

            _employeeHeader.BranchId        = employeeHeader.BranchId;
            _employeeHeader.ManagerId       = employeeHeader.ManagerId;
            _employeeHeader.FirstName       = !string.IsNullOrWhiteSpace(employeeHeader.FirstName) ? employeeHeader.FirstName.ToUpper() : string.Empty;
            _employeeHeader.MiddleName      = !string.IsNullOrWhiteSpace(employeeHeader.MiddleName) ? employeeHeader.MiddleName.ToUpper() : string.Empty;
            _employeeHeader.LastName        = !string.IsNullOrWhiteSpace(employeeHeader.LastName) ? employeeHeader.LastName.ToUpper() : string.Empty;
            _employeeHeader.Nationality     = !string.IsNullOrWhiteSpace(employeeHeader.Nationality) ? employeeHeader.Nationality : string.Empty;
            _employeeHeader.IDNumber        = !string.IsNullOrWhiteSpace(employeeHeader.IDNumber) ? employeeHeader.IDNumber : string.Empty;
            _employeeHeader.IDType          = employeeHeader.IDType;
            _employeeHeader.UserEmailId     = employeeHeader.UserEmailId;
            _employeeHeader.Password        = employeeHeader.Password;
            _employeeHeader.IsActive        = employeeHeader.IsActive;
            _employeeHeader.ConfirmPassword = employeeHeader.ConfirmPassword;
            _employeeHeader.EmployeePersonalInfo.Add(PrepareEmployeePersonalInfo(employeePersonalInfo, _employeeHeader));
            _employeeHeader.Address.Add(PrepareEmployeeAddress(employeeHeader.Address.FirstOrDefault(), _employeeHeader));
            _employeeHeader.EmployeeWorkDetail.Add(PrepareEmployeeWorkDetail(employeeHeader.EmployeeWorkDetail.FirstOrDefault(), _employeeHeader));
            employeeHeader.User  = employeeHeader.User == null ? new User() : employeeHeader.User;
            _employeeHeader.User = PrepareUserDetails(employeeHeader.User, _employeeHeader);

            List <EmployeeDocument> employeeDocument = employeeHeader.EmployeeDocument != null ? employeeHeader.EmployeeDocument : new List <EmployeeDocument>();

            PrepareEmployeeDocuments(hfc, _employeeHeader, employeeDocument, employeeDocumentViewModel);
            return(_employeeHeader);
        }
Пример #9
0
        //Edit Employee
        public ActionResult Edit(int EmployeeID)
        {
            Employee             employee             = employeeService.GetEmployeeById(EmployeeID);
            EmployeePersonalInfo employeePersonalInfo = employeeService.GetEmployeePersonalInfoById(EmployeeID);
            EmployeeViewModel    employeeViewModel    = new EmployeeViewModel()
            {
                EmployeeID = employee.EmployeeID,
                FirstName  = employee.FirstName,
                MiddleName = employee.MiddleName,
                LastName   = employee.LastName,
                //Department = employee.Department,
                Phone     = employeePersonalInfo.Phone,
                Email     = employee.Email,
                Gender    = employeePersonalInfo.Gender,
                Position  = employeePersonalInfo.Position,
                Address   = employeePersonalInfo.Address,
                HiredDate = employeePersonalInfo.HiredDate,
                //ResignationDate = employeePersonalInfo.ResignationDate
            };

            return(View(employeeViewModel));
        }
Пример #10
0
        private EmployeePersonalInfo PrepareEmployeePersonalInfo(EmployeePersonalInfo employeePersonalInfo, EmployeeHeader employeeHeader)
        {
            EmployeePersonalInfo _employeePersonalInfo = null;

            if (employeePersonalInfo.Id > 0)
            {
                _employeePersonalInfo            = employeeHeader.EmployeePersonalInfo.FirstOrDefault();
                _employeePersonalInfo.ModifiedBy = USER_OBJECT.UserID;
                _employeePersonalInfo.ModifiedOn = DateTimeConverter.SingaporeDateTimeConversion(DateTime.Now);
            }
            else
            {
                _employeePersonalInfo           = new EmployeePersonalInfo();
                _employeePersonalInfo.CreatedBy = USER_OBJECT.UserName;
                _employeePersonalInfo.CreatedOn = DateTimeConverter.SingaporeDateTimeConversion(DateTime.Now);
            }
            _employeePersonalInfo.BranchId = employeePersonalInfo.BranchId;
            //_employeePersonalInfo.EmployeeId = employeeHeader.Id;
            _employeePersonalInfo.DOB                    = DateTimeConverter.SingaporeDateTimeConversion(Convert.ToDateTime(employeePersonalInfo.DOB));
            _employeePersonalInfo.Gender                 = employeePersonalInfo.Gender;
            _employeePersonalInfo.FatherName             = employeePersonalInfo.FatherName;
            _employeePersonalInfo.BirthCountry           = employeePersonalInfo.BirthCountry;
            _employeePersonalInfo.MaritalStatus          = employeePersonalInfo.MaritalStatus;
            _employeePersonalInfo.SpouseName             = employeePersonalInfo.SpouseName;
            _employeePersonalInfo.EmergencyContactNumber = employeePersonalInfo.EmergencyContactNumber;
            _employeePersonalInfo.EmergencyContactName   = employeePersonalInfo.EmergencyContactName;
            if (employeePersonalInfo.MarriageDate.HasValue)
            {
                _employeePersonalInfo.MarriageDate = DateTimeConverter.SingaporeDateTimeConversion(employeePersonalInfo.MarriageDate.Value);
            }
            else
            {
                _employeePersonalInfo.MarriageDate = null;
            }
            _employeePersonalInfo.ResidentialStatus = employeePersonalInfo.ResidentialStatus;

            return(_employeePersonalInfo);
        }
Пример #11
0
        public void CheckWhetherLanguagesAreGettingUpdatedInEmployeeSave()
        {
            // ARRANGE
            var uow = Mock.Create <IQTecUnitOfWork>(Behavior.Loose);

            var employeeToBeUpdated = new Employee
            {
                DateOfBirth   = new DateTime(2012, 1, 1),
                DesignationId = 2,
                Email         = "*****@*****.**",
                FirstName     = "Abc",
                LastName      = "XYZ"
            };

            var employeePersonalDtoinParamater = new EmployeePersonalInfo
            {
                DateOfBirth   = new DateTime(2012, 1, 1),
                DesignationId = 2,
                Email         = "*****@*****.**",
                FirstName     = "AbcDef", // firstname is changed
                LastName      = "XYZ"
            };

            Mock.Arrange(() => uow.EmployeeRepository.GetById(Arg.AnyInt)).Returns(employeeToBeUpdated);

            var currentEmployeeLanguagesKnown = new List <EmployeeLanguages>
            {
                new EmployeeLanguages
                {
                    EmployeeId = 1,
                    Fluency    = 1,
                    LanguageId = 1
                },
                new EmployeeLanguages
                {
                    EmployeeId = 1,
                    Fluency    = 1,
                    LanguageId = 2
                }
            };

            Mock.Arrange(() => uow.EmployeeLanguagesRepository.GetAll()).Returns(currentEmployeeLanguagesKnown.AsQueryable);

            //// updating fluency from 1 to 2
            var employeeLanguagesInfoParamater = new List <EmployeeLanguageInfo>
            {
                new EmployeeLanguageInfo
                {
                    EmployeeId = 1,
                    Fluency    = (Fluency)2,
                    LanguageId = 1
                },
                new EmployeeLanguageInfo
                {
                    EmployeeId = 1,
                    Fluency    = (Fluency)2,
                    LanguageId = 2
                }
            };

            Mock.Arrange(() => uow.EmployeeLanguagesRepository.Update(Arg.IsAny <EmployeeLanguages>())).DoInstead(
                () =>
            {
                foreach (var employeeLanguageInfo in employeeLanguagesInfoParamater)
                {
                    var languageToBeUpdated =
                        currentEmployeeLanguagesKnown.FirstOrDefault(
                            lang => lang.EmployeeId == 1 && lang.LanguageId == employeeLanguageInfo.LanguageId);

                    if (languageToBeUpdated != null)
                    {
                        languageToBeUpdated.Fluency = (int)employeeLanguageInfo.Fluency;
                    }
                }
            });

            // ACT
            var classunderTest = new EmployeeManager(uow);

            classunderTest.SaveEmployee(1, employeePersonalDtoinParamater, employeeLanguagesInfoParamater);


            // ASSERT
            var firstOrDefault = currentEmployeeLanguagesKnown.FirstOrDefault();

            if (firstOrDefault != null)
            {
                Assert.AreEqual(2, firstOrDefault.Fluency);
            }

            Mock.Assert(uow);
        }
Пример #12
0
 public void RemoveEmployeePersonal(EmployeePersonalInfo dataToBeDeleted)
 {
     employeePersonalInfoTableActions.RemoveEmployee(dataToBeDeleted);
 }
Пример #13
0
        public List <Employee> ReadEmployeeFromDepartmentFromDB(EmployeeDepartment department)
        {
            List <Employee>         employees = new List <Employee>();
            List <EmployeeContract> contracts = new List <EmployeeContract>();

            try
            {
                string       sql = $"SELECT FirstName, LastName, employee.EmployeeNumber, Department,  DateOfBirth, City, Street, HouseNumber, HouseNumberAddition, PostCode, Email, Phone, BSN, ICEName, ICEPhone, Password FROM employee INNER JOIN employeeemploymentinfo ON employee.EmployeeNumber = employeeemploymentinfo.EmployeeNumber INNER JOIN empoyeepersonalinfo ON employee.EmployeeNumber = empoyeepersonalinfo.EmployeeNumber WHERE Department='{department}';";
                MySqlCommand cmd = new MySqlCommand(sql, conn);

                string       contract    = "SELECT EmployeeNumber, FTE, Salary, StartDate, EndDate, EndReason, IsActive, ContractNumber FROM contract;";
                MySqlCommand cmdcontract = new MySqlCommand(contract, conn);

                conn.Open();

                MySqlDataReader dr = cmd.ExecuteReader();

                while (dr.Read())
                {
                    Address adress = new Address(dr[6].ToString(), Convert.ToInt32(dr[7]), dr[8].ToString(), dr[9].ToString(), dr[5].ToString());
                    EmployeePersonalInfo          persInfo = new EmployeePersonalInfo(Convert.ToDateTime(dr[4]), dr[11].ToString(), adress, dr[10].ToString(), dr[12].ToString(), dr[13].ToString(), dr[14].ToString(), dr[15].ToString());
                    EmployeeEmploymentInformation emplInfo = new EmployeeEmploymentInformation((EmployeeDepartment)Enum.Parse(typeof(EmployeeDepartment), dr[3].ToString()));
                    Employee e = new Employee(dr[0].ToString(), dr[1].ToString(), emplInfo, persInfo, Convert.ToInt32(dr[2]));
                    employees.Add(e);
                }
                dr.Close();

                MySqlDataReader drcontr = cmdcontract.ExecuteReader();
                while (drcontr.Read())
                {
                    if (Convert.ToBoolean(drcontr[6]))
                    {
                        EmployeeContract eca = new EmployeeContract(Convert.ToDouble(drcontr[1]), Convert.ToDouble(drcontr[2]), Convert.ToDateTime(drcontr[3]), Convert.ToInt32(drcontr[0]), drcontr[7].ToString());
                        contracts.Add(eca);
                    }
                    else
                    {
                        EmployeeContract ec = new EmployeeContract(Convert.ToDouble(drcontr[1]), Convert.ToDouble(drcontr[2]), Convert.ToDateTime(drcontr[3]), Convert.ToDateTime(drcontr[4]), drcontr[5].ToString(), Convert.ToBoolean(drcontr[6]), Convert.ToInt32(drcontr[0]), drcontr[7].ToString());
                        contracts.Add(ec);
                    }
                }
                dr.Close();


                foreach (EmployeeContract c in contracts)
                {
                    foreach (Employee e in employees)
                    {
                        if (e.EmployeeNumber == c.EmplNum)
                        {
                            e.employmentInfo.InitializeContractHistory(c);
                        }
                    }
                }
            }
            catch (MySqlException ex)
            {
                throw ex;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(employees);
        }
Пример #14
0
        public bool SaveEmployee(int employeeId, EmployeePersonalInfo personalInfo, List <EmployeeLanguageInfo> employeeLanguageListInfo)
        {
            if (!personalInfo.IsValid())
            {
                throw new BusinessRulesException(personalInfo.Errors.ToErrorMessage());
            }

            if (employeeId > 0) // update employee
            {
                var employeetobeUpdated  = this.qTecUnitOfWork.EmployeeRepository.GetById(employeeId);
                var languagesToBeDeleted = new List <EmployeeLanguages>();
                if (employeetobeUpdated != null && personalInfo != null)
                {
                    //// TODO Use Auto Mapper so that this conversion doesn't take place
                    employeetobeUpdated.FirstName     = personalInfo.FirstName;
                    employeetobeUpdated.LastName      = personalInfo.LastName;
                    employeetobeUpdated.EmployeeId    = employeeId;
                    employeetobeUpdated.Email         = personalInfo.Email;
                    employeetobeUpdated.DesignationId = personalInfo.DesignationId;
                }


                //// get list of current employee languages which are not available in the employeeLanguageListInfo param

                if (employeetobeUpdated != null && employeeLanguageListInfo != null)
                {
                    var employeeLanguages =
                        this.qTecUnitOfWork.EmployeeLanguagesRepository.GetAll().Where(employeeLanguage => employeeLanguage.EmployeeId.Equals(employeetobeUpdated.EmployeeId));

                    foreach (var employeeLanguage in employeeLanguages)
                    {
                        var langId = employeeLanguage.LanguageId;
                        var found  = false;

                        if (employeeLanguageListInfo != null)
                        {
                            foreach (var languageInfo in employeeLanguageListInfo)
                            {
                                if (languageInfo.LanguageId.Equals(langId))
                                {
                                    found = true; //// language is present in the employeeLanguages
                                }
                            }
                        }

                        if (!found)
                        {
                            //// language is not found so add it in the list of deleted
                            languagesToBeDeleted.Add(employeeLanguage);
                        }
                    }
                    foreach (var employeeLanguage in languagesToBeDeleted)
                    {
                        this.qTecUnitOfWork.EmployeeLanguagesRepository.Delete(employeeLanguage);
                    }

                    if (employeeLanguageListInfo != null)
                    {
                        foreach (var employeeLanguageInfo in employeeLanguageListInfo)
                        {
                            var languageTobeUpdated =
                                employeeLanguages.FirstOrDefault(
                                    e =>
                                    e.EmployeeId.Equals(employeeId) && e.LanguageId.Equals(employeeLanguageInfo.LanguageId));

                            //var languageTobeUpdated =this.qTecUnitOfWork.EmployeeLanguagesRepository.GetById(employeeLanguageInfo.LanguageId);

                            if (languageTobeUpdated != null)
                            {
                                this.qTecUnitOfWork.EmployeeLanguagesRepository.Update(languageTobeUpdated);
                            }
                            else
                            {
                                //// the language is not found in the current languages collection that is associated with the employee so add a new
                                this.qTecUnitOfWork.EmployeeLanguagesRepository.Add(new EmployeeLanguages
                                {
                                    EmployeeId = employeeLanguageInfo.EmployeeId,
                                    Fluency    = (int)employeeLanguageInfo.Fluency,
                                    LanguageId = employeeLanguageInfo.LanguageId
                                });
                            }
                        }
                    }
                }

                this.qTecUnitOfWork.EmployeeRepository.Update(employeetobeUpdated);
                this.qTecUnitOfWork.Commit();
                return(true);
            }
            return(false);
        }
Пример #15
0
        public ActionResult Edit(HttpPostedFileBase profileFile, EmployeeModel reporter)
        {
            reporter.UniqueTitle = VITV.Web.Helpers.UrlHelper.URLFriendly(reporter.Name);
            if (profileFile != null && profileFile.ContentLength > 0)
            {
                string fileName      = Convert.ToInt32((DateTime.Now - new DateTime(2010, 01, 01)).TotalSeconds) + "_" + profileFile.FileName;
                string currentDomain = System.Configuration.ConfigurationManager.AppSettings["CurrentDomain"];
                string folder        = "UploadedImages/profilepicture";
                string filePath      = System.Configuration.ConfigurationManager.AppSettings[currentDomain] + @"\" + folder + @"\" + fileName;

                using (new Impersonator("uploaduser", "", "Upload@@123"))
                {
                    profileFile.SaveAs(filePath);
                }
                reporter.ProfilePicture = currentDomain + "/" + folder + "/" + fileName;
            }
            else if (String.IsNullOrEmpty(reporter.ProfilePicture))
            {
                reporter.ProfilePicture = "/Images/default-avatar.png";
            }

            ModelState.Clear();
            TryValidateModel(reporter);

            if (ModelState.IsValid)
            {
                var reporterEn = AutoMapper.Mapper.Map <EmployeeModel, Employee>(reporter);
                _reporterRepository.Load(reporterEn, a => a.Roles);
                if (reporter.Roles != null)
                {
                    List <Role> lstTemp = reporterEn.Roles.ToList();
                    foreach (Role r in lstTemp)
                    {
                        reporterEn.Roles.Remove(r);
                    }

                    foreach (int i in reporter.Roles)
                    {
                        Role r = _roleRepository.Find(i);
                        reporterEn.Roles.Add(r);
                    }
                }
                else
                {
                    List <Role> lstTemp = reporterEn.Roles.ToList();
                    foreach (Role r in lstTemp)
                    {
                        reporterEn.Roles.Remove(r);
                    }
                }
                var personalInfo = context.EmployeePersonalInfos.Find(reporter.Id);
                if (personalInfo == null)
                {
                    personalInfo = new EmployeePersonalInfo
                    {
                        Id = reporter.Id
                    };
                }
                personalInfo.Biography    = reporter.Biography;
                personalInfo.Email        = reporter.Email;
                personalInfo.Introduction = reporter.Introduction;
                personalInfo.Phone        = reporter.Phone;


                _reporterRepository.InsertOrUpdate(reporterEn);
                _reporterRepository.InsertOrUpdate(personalInfo);
                _reporterRepository.Save();
                return(RedirectToAction("Management"));
            }
            return(View(reporter));
        }
Пример #16
0
        private void btnSaveEmployee_Click(object sender, EventArgs e)
        {
            try
            {
                string             fn         = tbxFirstName.Text;
                string             ln         = tbxLastName.Text;
                EmployeeDepartment ed         = (EmployeeDepartment)comboBoxDepartment.SelectedIndex;
                double             fte        = Convert.ToDouble(numericUpDownHoursPerWeek.Value);
                double             salary     = Convert.ToDouble(numericUpDownSalary.Value);
                DateTime           sd         = dtpStartDate.Value;
                DateTime           bd         = dtpDateOfBirth.Value;
                string             phone      = tbxPhoneNumber.Text;
                string             city       = tbCity.Text;
                string             streetname = tbxStreetName.Text;
                int    streetnum    = Convert.ToInt32(tbxStreetNumber.Text);
                string streetnumadd = tbxStreetNrAddition.Text;
                string postcode     = tbxPostalCode.Text;
                string email        = tbxEmail.Text;
                string bsn          = tbxBSN.Text;
                string icename      = tbxEmergencyName.Text;
                string icephone     = tbxEmergencyPhone.Text;



                if (lbEmplNum.Text == "It will be generated automatically.")
                {
                    EmployeeEmploymentInformation emploInfo = new EmployeeEmploymentInformation(ed, new EmployeeContract(fte, salary, sd, newEmplNum, $"{newEmplNum}.{1}"));
                    EmployeePersonalInfo          persInfo  = new EmployeePersonalInfo(bd, phone, new Address(streetname, streetnum, streetnumadd, postcode, city), email, bsn, icename, icephone);
                    Employee employee = new Employee(fn, ln, emploInfo, persInfo, newEmplNum);
                    if (em.AddEmployee(employee))
                    {
                        MessageBox.Show("New employee was added successfully.");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Something went wrong.");
                    }
                }
                else
                {
                    empl.employmentInfo.EditActiveContract(new EmployeeContract(fte, salary, sd, empl.EmployeeNumber, empl.employmentInfo.GetActiveContract().ContractNum));
                    EmployeeEmploymentInformation emploInfo = new EmployeeEmploymentInformation(ed, empl.employmentInfo.GetContractHistory().ToList());
                    EmployeePersonalInfo          persInfo  = new EmployeePersonalInfo(bd, phone, new Address(streetname, streetnum, streetnumadd, postcode, city), email, bsn, icename, icephone);
                    Employee employee = new Employee(fn, ln, emploInfo, persInfo, empl.EmployeeNumber);
                    if (em.EditEmployee(this.empl, employee))
                    {
                        MessageBox.Show("Employee was edited successfully.");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Something went wrong.");
                    }
                }
            }
            //catch (CustomeExeptions.InvalidPhoneNumEx ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
            //catch (CustomeExeptions.InvalidEmailEx ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
            //catch (CustomeExeptions.InvalidPostcodeEx ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
            //catch (CustomExceptions.InvalidBSNEx ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
            //catch (MySqlException ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }