Esempio n. 1
0
        public void Validate(Infrastructure.LcpsDbContext context)
        {
            // ---------- Validate Position Info

            try
            {
                _staffDefinition = new HRStaffPositionDefinition(this.BuildingId, this.EmployeeTypeId, this.JobTitleId, context);
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                ValidationReport = ec.ToLineBreakString();
                ValidationStatus = ImportRecordStatus.danger;
                return;
            }

            // ---------- Valdiate Birthdate
            try
            {
                DateTime d = this.Birthdate;
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(new Exception("Invalid bithdate", ex));
                ValidationReport = ec.ToLineBreakString();
                ValidationStatus = ImportRecordStatus.danger;
                return;
            }

            // ---------- Valdiate Status Qualifier
            try
            {
                HRStaffPositionQualifier q = this.Status;
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(new Exception("Invalid status", ex));
                ValidationReport = ec.ToLineBreakString();
                ValidationStatus = ImportRecordStatus.danger;
                return;
            }

            // ---------- Validate gender
            try
            {
                HRGenders g = this.Gender;
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(new Exception("Invalid gender", ex));
                ValidationReport = ec.ToLineBreakString();
                ValidationStatus = ImportRecordStatus.danger;
                return;
            }

            // --------- Validate Required fields
            try
            {
                AnvilEntity e = new AnvilEntity(this);
                e.RequiredFields.Add("StaffId");
                e.RequiredFields.Add("FirstName");
                e.RequiredFields.Add("LastName");

                e.Validate();
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                ValidationReport = ec.ToLineBreakString();
                ValidationStatus = ImportRecordStatus.danger;
                return;

            }

            ValidationStatus = ImportRecordStatus.success;
            ValidationReport = "Validated";
        }
        public void Validate(Infrastructure.LcpsDbContext context)
        {
            // ---------- Vadliate User key
            HRStaff staff = context.StaffMembers.FirstOrDefault(x => x.StaffId.ToLower() == this.EntityId.ToLower());
            if (staff == null)
            {
                Student stu = context.Students.FirstOrDefault(x => x.StudentId.ToLower() == this.EntityId.ToLower());
                if (stu == null)
                {
                    ValidationReport = string.Format("{0} is not a valida student or staff id", this.EntityId);
                    ValidationStatus = ImportRecordStatus.danger;
                    return;
                }
                else
                    _userKey = stu.StudentKey;

            }
            else _userKey = staff.StaffKey;

            // ---------- Validate Fields
            try
            {
                AnvilEntity e = new AnvilEntity(this);
                e.RequiredFields.Add("StaffId");
                e.RequiredFields.Add("UserName");
                e.RequiredFields.Add("Password");
                e.Validate();
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                ValidationReport = ec.ToLineBreakString();
                ValidationStatus = ImportRecordStatus.danger;
                return;
            }

            // ---------- Validate Password
            if(this.Password.Length < 6)
            {
                ValidationReport = "The password must contain at least 6 characters";
                ValidationStatus = ImportRecordStatus.danger;
                return;
            }

            ValidationReport = "Validated";
            ValidationStatus = ImportRecordStatus.success;
        }