Exemple #1
0
        public void FillEmployeeLocations(Employee employee, ViewModels.Employee dto)
        {
            var exists      = this.context.EmployeeLocations.Where(q => q.EmployeeId == employee.Id).ToList();
            var dtoLocation = dto.Locations.First();

            if (exists == null || exists.Count == 0)
            {
                employee.EmployeeLocations.Add(new EmployeeLocation()
                {
                    DateActiveEnd    = dtoLocation.DateActiveEnd,
                    DateActiveEndP   = dtoLocation.DateActiveEnd != null ? (Nullable <decimal>)Convert.ToDecimal(Utils.DateTimeUtil.GetPersianDateTimeDigital((DateTime)dtoLocation.DateActiveEnd)) : null,
                    DateActiveStart  = dtoLocation.DateActiveStart,
                    DateActiveStartP = dtoLocation.DateActiveStart != null ? (Nullable <decimal>)Convert.ToDecimal(Utils.DateTimeUtil.GetPersianDateTimeDigital((DateTime)dtoLocation.DateActiveStart)) : null,
                    IsMainLocation   = dtoLocation.IsMainLocation,
                    LocationId       = dtoLocation.LocationId,
                    OrgRoleId        = dtoLocation.OrgRoleId,
                    Phone            = dtoLocation.Phone,
                    Remark           = dtoLocation.Remark
                });
            }
            else
            {
                exists[0].DateActiveEnd    = dtoLocation.DateActiveEnd;
                exists[0].DateActiveEndP   = dtoLocation.DateActiveEnd != null ? (Nullable <decimal>)Convert.ToDecimal(Utils.DateTimeUtil.GetPersianDateTimeDigital((DateTime)dtoLocation.DateActiveEnd)) : null;
                exists[0].DateActiveStart  = dtoLocation.DateActiveStart;
                exists[0].DateActiveStartP = dtoLocation.DateActiveStart != null ? (Nullable <decimal>)Convert.ToDecimal(Utils.DateTimeUtil.GetPersianDateTimeDigital((DateTime)dtoLocation.DateActiveStart)) : null;
                exists[0].IsMainLocation   = dtoLocation.IsMainLocation;
                exists[0].LocationId       = dtoLocation.LocationId;
                exists[0].OrgRoleId        = dtoLocation.OrgRoleId;
                exists[0].Phone            = dtoLocation.Phone;
                exists[0].Remark           = dtoLocation.Remark;
            }
        }
Exemple #2
0
        public static void Fill(Models.PersonCustomer entity, ViewModels.Employee personcustomer)
        {
            entity.Id              = personcustomer.Id;
            entity.PersonId        = personcustomer.PersonId;
            entity.DateJoinCompany = personcustomer.DateJoinCompany;
            if (personcustomer.DateJoinCompany != null)
            {
                entity.DateJoinCompanyP = Convert.ToDecimal(Utils.DateTimeUtil.GetPersianDateDigital((DateTime)personcustomer.DateJoinCompany));
            }
            entity.IsActive = personcustomer.IsActive;

            if (entity.Id == -1)
            {
                entity.DateRegister   = DateTime.Now;
                entity.DateRegisterP  = Convert.ToDecimal(Utils.DateTimeUtil.GetPersianDateTimeDigital((DateTime)entity.DateRegister));
                entity.DateConfirmed  = personcustomer.DateRegister;
                entity.DateConfirmedP = entity.DateRegisterP;
            }


            entity.IsDeleted       = personcustomer.IsDeleted;
            entity.DateActiveStart = personcustomer.DateActiveStart;
            entity.DateActiveEnd   = personcustomer.DateActiveEnd;
            // entity.DateLastLoginP = personcustomer.DateLastLoginP;
            //entity.DateLastLogin = personcustomer.DateLastLogin;
            entity.Username   = personcustomer.PID;
            entity.Password   = personcustomer.PID;
            entity.CustomerId = personcustomer.CustomerId;
            entity.GroupId    = personcustomer.GroupId;
        }
Exemple #3
0
        public virtual CustomActionResult Validate(ViewModels.Employee dto)
        {
            //return Exceptions.getDuplicateException("Location-01", "Title");
            // var c = dbSet.FirstOrDefault(q => q.Id != dto.Id && q.DateStart == dto.DateStart && q.CourseTypeId == dto.CourseTypeId && q.OrganizationId == dto.OrganizationId);
            var c = dbSet.FirstOrDefault(q => q.Id != dto.Person.PersonId && q.NID == dto.Person.NID);

            if (c != null)
            {
                return(Exceptions.getDuplicateException("Person-01", "NID"));
            }
            if (!string.IsNullOrEmpty(dto.Person.IDNo))
            {
                var idno = dbSet.FirstOrDefault(q => q.Id != dto.Person.PersonId && q.IDNo == dto.Person.IDNo);
                if (idno != null)
                {
                    return(Exceptions.getDuplicateException("Person-02", "IDNo"));
                }
            }


            var pc = context.ViewEmployees.FirstOrDefault(q => q.CustomerId == dto.CustomerId && q.Id != dto.Id && q.PID == dto.PID);

            if (pc != null)
            {
                return(Exceptions.getDuplicateException("Employee-01", "PID"));
            }

            return(new CustomActionResult(HttpStatusCode.OK, ""));
        }
Exemple #4
0
 public static void Fill(Models.Employee entity, ViewModels.Employee employee)
 {
     entity.Id                = employee.Id;
     entity.InActive          = employee.InActive;
     entity.PID               = employee.PID;
     entity.Phone             = employee.Phone;
     entity.BaseAirportId     = employee.BaseAirportId;
     entity.DateInactiveBegin = employee.DateInactiveBegin;
     if (employee.DateInactiveEnd != null)
     {
         entity.DateInactiveEnd = ((DateTime)employee.DateInactiveEnd).Date.AddHours(23).AddMinutes(59).AddSeconds(59);
     }
 }
Exemple #5
0
        public void FillEducations(Person person, ViewModels.Employee dto)
        {
            var existing = this.context.PersonEducations.Where(q => q.PersonId == person.Id).ToList();
            var deleted  = (from x in existing
                            where dto.Person.Educations.FirstOrDefault(q => q.Id == x.Id) == null
                            select x).ToList();
            var added = (from x in dto.Person.Educations
                         where existing.FirstOrDefault(q => q.Id == x.Id) == null
                         select x).ToList();
            var edited = (from x in existing
                          where dto.Person.Educations.FirstOrDefault(q => q.Id == x.Id) != null
                          select x).ToList();

            foreach (var x in deleted)
            {
                context.PersonEducations.Remove(x);
            }
            foreach (var x in added)
            {
                context.PersonEducations.Add(new PersonEducation()
                {
                    Person            = person,
                    Remark            = x.Remark,
                    College           = x.College,
                    DateCatch         = x.DateCatch,
                    EducationDegreeId = x.EducationDegreeId,
                    StudyFieldId      = x.StudyFieldId,
                    Title             = x.Title,
                    FileTitle         = x.FileTitle,
                    FileType          = x.FileType,
                    FileUrl           = x.FileUrl,
                    SysUrl            = x.SysUrl,
                });
            }
            foreach (var x in edited)
            {
                var item = dto.Person.Educations.FirstOrDefault(q => q.Id == x.Id);
                if (item != null)
                {
                    x.College           = item.College;
                    x.DateCatch         = item.DateCatch;
                    x.EducationDegreeId = item.EducationDegreeId;
                    x.StudyFieldId      = item.StudyFieldId;
                    x.Remark            = item.Remark;
                    x.FileTitle         = item.FileTitle;
                    x.FileType          = item.FileType;
                    x.FileUrl           = item.FileUrl;
                    x.SysUrl            = item.SysUrl;
                }
            }
        }
Exemple #6
0
        public void FillExps(Person person, ViewModels.Employee dto)
        {
            var existing = this.context.PersonExperienses.Where(q => q.PersonId == person.Id).ToList();
            var deleted  = (from x in existing
                            where dto.Person.Expreienses.FirstOrDefault(q => q.Id == x.Id) == null
                            select x).ToList();
            var added = (from x in dto.Person.Expreienses
                         where existing.FirstOrDefault(q => q.Id == x.Id) == null
                         select x).ToList();
            var edited = (from x in existing
                          where dto.Person.Expreienses.FirstOrDefault(q => q.Id == x.Id) != null
                          select x).ToList();

            foreach (var x in deleted)
            {
                context.PersonExperienses.Remove(x);
            }
            foreach (var x in added)
            {
                context.PersonExperienses.Add(new PersonExperiense()
                {
                    Person         = person,
                    Remark         = x.Remark,
                    AircraftTypeId = x.AircraftTypeId,
                    DateEnd        = x.DateEnd,
                    DateStart      = x.DateStart,
                    Employer       = x.Employer,
                    JobTitle       = x.JobTitle,
                    Organization   = x.Organization,
                    OrganizationId = x.OrganizationId,
                });
            }
            foreach (var x in edited)
            {
                var item = dto.Person.Expreienses.FirstOrDefault(q => q.Id == x.Id);
                if (item != null)
                {
                    x.AircraftTypeId = item.AircraftTypeId;
                    x.DateEnd        = item.DateEnd;
                    x.DateStart      = item.DateStart;
                    x.Employer       = item.Employer;
                    x.JobTitle       = item.JobTitle;
                    x.Organization   = item.Organization;
                    x.OrganizationId = item.OrganizationId;
                    x.Remark         = item.Remark;
                }
            }
        }
Exemple #7
0
        public void FillRatings(Person person, ViewModels.Employee dto)
        {
            var existing = this.context.PersonRatings.Where(q => q.PersonId == person.Id).ToList();
            var deleted  = (from x in existing
                            where dto.Person.Ratings.FirstOrDefault(q => q.Id == x.Id) == null
                            select x).ToList();
            var added = (from x in dto.Person.Ratings
                         where existing.FirstOrDefault(q => q.Id == x.Id) == null
                         select x).ToList();
            var edited = (from x in existing
                          where dto.Person.Ratings.FirstOrDefault(q => q.Id == x.Id) != null
                          select x).ToList();

            foreach (var x in deleted)
            {
                context.PersonRatings.Remove(x);
            }
            foreach (var x in added)
            {
                context.PersonRatings.Add(new PersonRating()
                {
                    Person = person,

                    AircraftTypeId = x.AircraftTypeId,

                    OrganizationId = x.OrganizationId,
                    CategoryId     = x.CategoryId,
                    DateExpire     = x.DateExpire,
                    DateIssue      = x.DateIssue,
                    RatingId       = x.RatingId,
                });
            }
            foreach (var x in edited)
            {
                var item = dto.Person.Ratings.FirstOrDefault(q => q.Id == x.Id);
                if (item != null)
                {
                    x.AircraftTypeId = item.AircraftTypeId;

                    x.OrganizationId = item.OrganizationId;
                    x.CategoryId     = item.CategoryId;
                    x.DateExpire     = item.DateExpire;
                    x.DateIssue      = item.DateIssue;
                    x.RatingId       = item.RatingId;
                }
            }
        }
Exemple #8
0
        public void FillAircraftTypes(Person person, ViewModels.Employee dto)
        {
            var existing = this.context.PersonAircraftTypes.Where(q => q.PersonId == person.Id).ToList();
            var deleted  = (from x in existing
                            where dto.Person.AircraftTypes.FirstOrDefault(q => q.Id == x.Id) == null
                            select x).ToList();
            var added = (from x in dto.Person.AircraftTypes
                         where existing.FirstOrDefault(q => q.Id == x.Id) == null
                         select x).ToList();
            var edited = (from x in existing
                          where dto.Person.AircraftTypes.FirstOrDefault(q => q.Id == x.Id) != null
                          select x).ToList();

            foreach (var x in deleted)
            {
                context.PersonAircraftTypes.Remove(x);
            }
            foreach (var x in added)
            {
                context.PersonAircraftTypes.Add(new PersonAircraftType()
                {
                    Person         = person,
                    AircraftTypeId = x.AircraftTypeId,
                    IsActive       = x.IsActive,
                    Remark         = x.Remark,
                    DateLimitBegin = x.DateLimitBegin,
                    DateLimitEnd   = x.DateLimitEnd
                });
            }
            foreach (var x in edited)
            {
                var item = dto.Person.AircraftTypes.FirstOrDefault(q => q.Id == x.Id);
                if (item != null)
                {
                    x.AircraftTypeId = item.AircraftTypeId;
                    x.DateLimitBegin = item.DateLimitBegin;
                    x.DateLimitEnd   = item.DateLimitEnd;
                    x.IsActive       = item.IsActive;
                    x.Remark         = item.Remark;
                }
            }
        }
Exemple #9
0
 public static void Fill(Models.Employee entity, ViewModels.Employee employee)
 {
     entity.Id    = employee.Id;
     entity.PID   = employee.PID;
     entity.Phone = employee.Phone;
 }
        public async Task <IHttpActionResult> PostEmployee(ViewModels.Employee dto)
        {
            // return Ok(client);
            if (dto == null)
            {
                return(Exceptions.getNullException(ModelState));
            }
            if (!ModelState.IsValid)
            {
                // return BadRequest(ModelState);
                return(Exceptions.getModelValidationException(ModelState));
            }
            var validate = unitOfWork.PersonRepository.Validate(dto);

            if (validate.Code != HttpStatusCode.OK)
            {
                return(validate);
            }

            ///////////////////////////////////////
            //   if (dto.Person.VisaExpireDate!=null)
            //    dto.Person.VisaExpireDate=((DateTime)dto.Person.VisaExpireDate).AddHours(3).AddMinutes(30);
            ///////////////////////////////////////////
            Person person = null;

            if (dto.PersonId != -1)
            {
                person = await unitOfWork.PersonRepository.GetPersonById(dto.PersonId);
            }
            else
            {
                person = await unitOfWork.PersonRepository.GetPersonByNID(dto.Person.NID);
            }
            if (person == null)
            {
                person            = new Person();
                person.DateCreate = DateTime.Now;
                unitOfWork.PersonRepository.Insert(person);
            }
            ViewModels.Person.Fill(person, dto.Person);
            PersonCustomer personCustomer = await unitOfWork.PersonRepository.GetPersonCustomer((int)dto.CustomerId, dto.Person.PersonId);

            if (personCustomer == null)
            {
                personCustomer = new PersonCustomer();

                person.PersonCustomers.Add(personCustomer);
            }
            ViewModels.PersonCustomer.Fill(personCustomer, dto);
            Employee employee = await unitOfWork.PersonRepository.GetEmployee(personCustomer.Id);

            if (employee == null)
            {
                employee = new Employee();
            }
            personCustomer.Employee = employee;
            ViewModels.Employee.Fill(employee, dto);
            unitOfWork.PersonRepository.FillEmployeeLocations(employee, dto);

            unitOfWork.PersonRepository.FillAircraftTypes(person, dto);
            unitOfWork.PersonRepository.FillDocuments(person, dto);
            unitOfWork.PersonRepository.FillEducations(person, dto);
            unitOfWork.PersonRepository.FillExps(person, dto);
            unitOfWork.PersonRepository.FillRatings(person, dto);



            var saveResult = await unitOfWork.SaveAsync();

            if (saveResult.Code != HttpStatusCode.OK)
            {
                return(saveResult);
            }

            dto.Id = employee.Id;
            return(Ok(dto));
        }
Exemple #11
0
        internal async Task <ViewModels.Employee> GetEmployeeDtoByNID(string nid, int cid)
        {
            ViewModels.Employee employee = null;
            var entity = await this.context.People.SingleOrDefaultAsync(q => q.NID == nid && !q.IsDeleted);

            if (entity == null)
            {
                return(null);
            }
            employee        = new ViewModels.Employee();
            employee.Person = new ViewModels.Person();
            ViewModels.Person.FillDto(entity, employee.Person);
            var actypes = await context.ViewPersonAircraftTypes.Where(q => q.PersonId == entity.Id).ToListAsync();

            employee.Person.AircraftTypes = ViewModels.PersonAircraftType.GetDtos(actypes);
            var educations = await context.ViewPersonEducations.Where(q => q.PersonId == entity.Id).ToListAsync();

            employee.Person.Educations = ViewModels.PersonEducation.GetDtos(educations);
            var exp = await context.ViewPersonExperienses.Where(q => q.PersonId == entity.Id).ToListAsync();

            employee.Person.Expreienses = ViewModels.PersonExperiense.GetDtos(exp);
            var rating = await context.ViewPersonRatings.Where(q => q.PersonId == entity.Id).ToListAsync();

            employee.Person.Ratings = ViewModels.PersonRating.GetDtos(rating);
            var doc = await context.ViewPersonDocuments.Where(q => q.PersonId == entity.Id).ToListAsync();

            var docIds = doc.Select(q => q.Id).ToList();
            var files  = await context.ViewPersonDocumentFiles.Where(q => q.PersonId == entity.Id).ToListAsync();

            employee.Person.Documents = ViewModels.PersonDocument.GetDtos(doc, files);
            var certificates = await this.context.ViewCertificates.Where(q => q.PersonId == entity.Id && q.IsLast == 1).OrderBy(q => q.ExpireStatus).ThenBy(q => q.Remain).ToListAsync();

            employee.Person.Certificates = certificates;
            var pc = context.PersonCustomers.SingleOrDefault(q => q.CustomerId == cid && q.PersonId == entity.Id && !q.IsDeleted);

            if (pc != null)
            {
                var emp = await context.Employees.FirstOrDefaultAsync(q => q.Id == pc.Id);

                if (emp != null)
                {
                    employee.CustomerId       = cid;
                    employee.DateActiveEnd    = pc.DateActiveEnd;
                    employee.DateActiveStart  = pc.DateActiveStart;
                    employee.DateJoinCompany  = pc.DateJoinCompany;
                    employee.DateJoinCompanyP = pc.DateJoinCompanyP;
                    employee.DateConfirmedP   = pc.DateConfirmedP;
                    employee.DateConfirmed    = pc.DateConfirmed;
                    employee.DateLastLogin    = pc.DateLastLogin;
                    employee.DateLastLoginP   = pc.DateLastLoginP;
                    employee.DateRegister     = pc.DateRegister;
                    employee.DateRegisterP    = pc.DateRegisterP;
                    employee.Id       = pc.Id;
                    employee.IsActive = pc.IsActive;
                    employee.Password = pc.Password;
                    employee.PersonId = entity.Id;
                    employee.GroupId  = pc.GroupId;
                    employee.PID      = emp.PID;
                    employee.Phone    = emp.Phone;
                    var locs = await context.ViewEmployeeLocations.Where(q => q.EmployeeId == pc.Id).ToListAsync();

                    employee.Locations = ViewModels.EmployeeLocation.GetDtos(locs);
                }
            }



            return(employee);
        }
Exemple #12
0
        public void FillDocuments(Person person, ViewModels.Employee dto)
        {
            var existing = this.context.PersonDocuments.Include("Documents").Where(q => q.PersonId == person.Id).ToList();
            var deleted  = (from x in existing
                            where dto.Person.Documents.FirstOrDefault(q => q.Id == x.Id) == null
                            select x).ToList();
            var added = (from x in dto.Person.Documents
                         where existing.FirstOrDefault(q => q.Id == x.Id) == null
                         select x).ToList();
            var edited = (from x in existing
                          where dto.Person.Documents.FirstOrDefault(q => q.Id == x.Id) != null
                          select x).ToList();

            foreach (var x in deleted)
            {
                context.PersonDocuments.Remove(x);
            }
            foreach (var x in added)
            {
                var pd = new PersonDocument()
                {
                    Person = person,

                    Remark         = x.Remark,
                    DocumentTypeId = x.DocumentTypeId,
                    Title          = x.Title,
                };
                foreach (var file in x.Documents)
                {
                    pd.Documents.Add(new Document()
                    {
                        FileType = file.FileType,
                        FileUrl  = file.FileUrl,
                        SysUrl   = file.SysUrl,
                        Title    = file.Title,
                    });
                }
                context.PersonDocuments.Add(pd);
            }
            foreach (var x in edited)
            {
                var item = dto.Person.Documents.FirstOrDefault(q => q.Id == x.Id);
                if (item != null)
                {
                    x.DocumentTypeId = item.DocumentTypeId;
                    x.Title          = item.Title;
                    x.Remark         = item.Remark;
                    //bani
                    while (x.Documents.Count > 0)
                    {
                        var f = x.Documents.First();
                        this.context.Documents.Remove(f);
                    }
                    foreach (var f in item.Documents)
                    {
                        x.Documents.Add(new Document()
                        {
                            FileType = f.FileType,
                            FileUrl  = f.FileUrl,
                            SysUrl   = f.SysUrl,
                            Title    = f.Title,
                        });
                    }
                }
            }
        }