Beispiel #1
0
        //Add new employee
        public bool Add(Employee employee)
        {
            if (string.IsNullOrEmpty(employee.Name) || employee.Name.Length < 3)
            {
                throw new Exception("Name should be at least 3 charecter");
            }

            if (string.IsNullOrEmpty(employee.Code))
            {
                throw new Exception("Code shoud be 7 charecter");
            }
            if (_employeeGetway.GetByCode(employee.Code) != null)
            {
                throw new Exception("Code should be unique");
            }
            //if (employee.BranchId < 1)
            //{
            //    throw new Exception("Branch is required");
            //}
            if (string.IsNullOrEmpty(employee.ContactNo) || employee.ContactNo.Length != 11)
            {
                throw new Exception("Contact no should be 11 digit");
            }
            if (_employeeGetway.GetByContactNo(employee.ContactNo) != null)
            {
                throw new Exception("Contact No should be unique");
            }
            if (_employeeGetway.GetByEmail(employee.Email) != null)
            {
                throw new Exception("Email should be unique");
            }
            if (string.IsNullOrEmpty(employee.NID) || (employee.NID.Length != 13 && employee.NID.Length != 17))
            {
                throw new Exception("NID should be 13 or 17 digit");
            }
            if (_employeeGetway.GetByNID(employee.NID) != null)
            {
                throw new Exception("NID should be unique");
            }

            return(_employeeGetway.Add(employee));
        }