/// <summary>
 /// Insert PersonCategory
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public async Task <int> InsertPersonCategoryAsync(PersonCategory entity)
 {
     using (var conn = OpenDBConnection())
     {
         StringBuilder sql = new StringBuilder();
         sql.Length = 0;
         sql.Append("INSERT INTO                                ");
         sql.Append("        PersonCategory (PersonId,          ");
         sql.Append("                        CategoryId,        ");
         sql.Append("                        OrderIndex,        ");
         sql.Append("                         CreatedAt,        ");
         sql.Append("                        UpdatedAt,         ");
         sql.Append("                        CreatedBy,         ");
         sql.Append("                        UpdatedBy)         ");
         sql.Append("OUTPUT INSERTED.ID                         ");
         sql.Append("VALUES (@PersonId,                         ");
         sql.Append("        @CategoryId,                       ");
         sql.Append("        @OrderIndex,                       ");
         sql.Append("        @CreatedAt,                        ");
         sql.Append("        @UpdatedAt,                        ");
         sql.Append("        @CreatedBy,                        ");
         sql.Append("        @UpdatedBy)                        ");
         var param = new
         {
             PersonId   = entity.PersonId,
             CategoryId = entity.CategoryId,
             OrderIndex = entity.OrderIndex,
             CreatedAt  = DateTime.Now,
             UpdatedAt  = DateTime.Now,
             CreatedBy  = entity.CreatedBy,
             UpdatedBy  = entity.UpdatedBy
         };
         return(await conn.ExecuteScalarAsync <int>(sql.ToString(), param));
     }
 }
        /// <summary>
        /// Check PersonCategory
        /// </summary>
        /// <param name="personCategory"></param>
        /// <returns></returns>
        public async Task <bool> CheckPersonCategoryAsync(PersonCategory personCategory)
        {
            using (var conn = OpenDBConnection())
            {
                StringBuilder sql = new StringBuilder();
                sql.Length = 0;
                sql.Append("SELECT COUNT(*)                                  ");
                sql.Append("FROM PersonCategory AS PC                        ");
                sql.Append("INNER JOIN Category AS CA                        ");
                sql.Append("ON PC.CategoryId = CA.Id                         ");
                sql.Append("WHERE PC.PersonId = @PersonId                    ");
                sql.Append("      AND PC.CategoryId = @CategoryId            ");
                sql.Append("      AND PC.Status = 1 AND CA.Status = 1        ");
                if (personCategory.Id > 0)
                {
                    sql.Append("      AND PC.Id != @Id                  ");
                }
                var param = new
                {
                    PersonId   = personCategory.PersonId,
                    CategoryId = personCategory.CategoryId,
                    Id         = personCategory.Id
                };
                int count = await conn.ExecuteScalarAsync <int>(sql.ToString(), param);

                return(count > 0);
            }
        }
        /// <summary>
        /// Delete PersonTechnology
        /// </summary>
        /// <param name="personCategory"></param>
        /// <returns></returns>
        public async Task <int> DeletePersonTechnologyAsync(PersonCategory personCategory)
        {
            using (var conn = OpenDBConnection())
            {
                StringBuilder sql = new StringBuilder();
                sql.Length = 0;
                sql.Append("UPDATE PersonTechnology                   ");
                sql.Append("SET Status        = 0,                    ");
                sql.Append("UpdatedBy         = @UpdatedBy,           ");
                sql.Append("UpdatedAt         = @UpdatedAt            ");
                sql.Append("FROM PersonTechnology AS PT               ");
                sql.Append("INNER JOIN Technology AS TE               ");
                sql.Append("ON PT.TechnologyId = TE.Id                ");
                sql.Append("WHERE PT.PersonId    = @PersonId          ");
                sql.Append("AND TE.CategoryId = @CategoryId           ");
                sql.Append("ANd PT.Status = 1                         ");
                var param = new
                {
                    UpdatedBy  = personCategory.UpdatedBy,
                    UpdatedAt  = personCategory.UpdatedAt,
                    PersonId   = personCategory.PersonId,
                    CategoryId = personCategory.CategoryId
                };
                var result = await conn.ExecuteAsync(sql.ToString(), param);

                return(result);
            }
        }
Exemple #4
0
        /// <summary>
        /// Delete Skill
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <SkillViewModel> DeleteSkill(int id)
        {
            model.AppResult.Result = false;
            PersonCategory personCategory = await _skillRepository.GetPersonCategoryAsync(id, null, null);

            if (personCategory != null)
            {
                var result = await _skillRepository.DeletePersonCategoryAsync(personCategory);

                if (result > 0)
                {
                    model.AppResult.Result = true;
                    await _skillRepository.DeletePersonTechnologyAsync(personCategory);

                    model.AppResult.Message = Constants.Constant.DELETE_SUCCESS;
                }
                else
                {
                    model.AppResult.Message = "Deletion failed, Skill not exists";
                }
            }
            else
            {
                model.AppResult.Message = "Deletion failed, Skill not exists";
            }
            return(model);
        }
Exemple #5
0
        /// <summary>
        /// Get Skill By Category
        /// </summary>
        /// <param name="personId"></param>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public async Task <IEnumerable <TechnologyResource> > GetSkillByCategory(int personId, int categoryId)
        {
            PersonCategory personCategory = new PersonCategory
            {
                PersonId   = personId,
                CategoryId = categoryId
            };
            IEnumerable <Technology> list = await _skillRepository.GetSkilByCategoryAsync(personCategory);

            List <TechnologyResource> listResult = new List <TechnologyResource>();

            if (list.Any())
            {
                foreach (var item in list)
                {
                    TechnologyResource technologyViewModel = new TechnologyResource
                    {
                        Id           = item.Id,
                        Name         = item.Name,
                        CategoryId   = item.Category.Id,
                        CategoryName = item.Category.Name
                    };
                    listResult.Add(technologyViewModel);
                }
            }
            return(listResult);
        }
 /// <summary>
 /// Delete PersonCategory
 /// </summary>
 /// <param name="personCategory"></param>
 /// <returns></returns>
 public async Task <int> DeletePersonCategoryAsync(PersonCategory personCategory)
 {
     using (var conn = OpenDBConnection())
     {
         StringBuilder sql = new StringBuilder();
         sql.Length = 0;
         sql.Append("UPDATE PersonCategory                       ");
         sql.Append("SET Status      = 0,                        ");
         sql.Append("UpdatedBy       = @UpdatedBy,               ");
         sql.Append("UpdatedAt       = @UpdatedAt                ");
         sql.Append("FROM PersonCategory AS PC                   ");
         sql.Append("INNER JOIN Category AS CA                   ");
         sql.Append("ON PC.CategoryId = CA.Id                    ");
         sql.Append("WHERE PC.PersonId  = @PersonId              ");
         sql.Append("AND PC.CategoryId  = @CategoryId            ");
         sql.Append("AND PC.Status = 1 AND CA.Status = 1         ");
         var param = new
         {
             UpdatedBy  = personCategory.UpdatedBy,
             UpdatedAt  = personCategory.UpdatedAt,
             PersonId   = personCategory.PersonId,
             CategoryId = personCategory.CategoryId,
         };
         return(await conn.ExecuteAsync(sql.ToString(), param));
     }
 }
 public bool Update(PersonCategory category)
 {
     try
     {
         return(_service.Update(category));
     }
     catch (Exception ex)
     {
         ex.WriterLog("TaskRelease.DAL", "PersonCategoryService", "Update");
         return(false);
     }
 }
Exemple #8
0
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            var pg   = ControlsFactory.Resolve <ManageCategoryPage>();
            var data = new PersonCategory();

            pg.GetModelData(data);
            DialogActivator.OpenDialog(pg, "New Category",
                                       () =>
            {
                HealthCenterService.CreateCategory(data);
            });
        }
        public void RunMatchingTest()
        {
            PersonCategory        pc10Male = new PersonCategory(10, PermittedGender.Male);
            PersonCategory        pc15Male = new PersonCategory(15, PermittedGender.Male);
            PersonCategory        pc20Male = new PersonCategory(20, PermittedGender.Male);
            PersonCategory        pc30Male = new PersonCategory(30, PermittedGender.Male);
            PersonCategory        pc31Male = new PersonCategory(31, PermittedGender.Male);
            PersonCategory        pc40Male = new PersonCategory(40, PermittedGender.Male);
            PersonCategory        pc41Male = new PersonCategory(41, PermittedGender.Male);
            List <PersonCategory> demand   = new List <PersonCategory>
            {
                pc10Male
            };

            {
                List <PersonCategory> offer = new List <PersonCategory>
                {
                    pc15Male
                };
                var success = HouseGenerator.AreOfferedCategoriesEnough(offer, demand);
                success.Should().BeTrue();
            }
            {
                List <PersonCategory> offer = new List <PersonCategory>
                {
                    pc20Male
                };
                var success = HouseGenerator.AreOfferedCategoriesEnough(offer, demand);
                success.Should().BeFalse();
            }
            demand.Clear();
            demand.Add(pc31Male);
            demand.Add(pc30Male);
            {
                List <PersonCategory> offer = new List <PersonCategory>
                {
                    pc40Male,
                    pc41Male
                };
                var success = HouseGenerator.AreOfferedCategoriesEnough(offer, demand);
                success.Should().BeTrue();
            }
            {
                List <PersonCategory> offer = new List <PersonCategory>
                {
                    pc40Male,
                    pc15Male
                };
                var success = HouseGenerator.AreOfferedCategoriesEnough(offer, demand);
                success.Should().BeFalse();
            }
        }
 /// <summary>
 /// Delete PersonTechnology to Update
 /// </summary>
 /// <param name="personCategory"></param>
 /// <returns></returns>
 public async Task <int> DeletePersonTechnologyToUpdateAsync(PersonCategory personCategory)
 {
     using (var conn = OpenDBConnection())
     {
         StringBuilder sql = new StringBuilder();
         sql.Length = 0;
         sql.Append("DELETE PT                                                     ");
         sql.Append("FROM PersonTechnology  AS PT                                  ");
         sql.Append("INNER JOIN Technology AS TE                                   ");
         sql.Append("ON PT.TechnologyId = TE.Id                                    ");
         sql.Append("WHERE PersonId = @PersonId AND TE.CategoryId = @CategoryId    ");
         var param = new
         {
             PersonId   = personCategory.PersonId,
             CategoryId = personCategory.CategoryId
         };
         return(await conn.ExecuteAsync(sql.ToString(), param));
     }
 }
Exemple #11
0
        private Person GetOrCreatePerson(string name, DateTime birthday, PersonCategory category, PersonType type)
        {
            var person = _db.People.SingleOrDefault(p => p.Name == name && p.Birthday == birthday);

            if (person == null)
            {
                person = new Person
                {
                    Name     = name,
                    Birthday = birthday,
                    Type     = type,
                    Category = category
                };
                _db.People.Add(person);
                _db.SaveChanges();
            }

            return(person);
        }
        /// <summary>
        /// Get Skill By Category
        /// </summary>
        /// <param name="personCategory"></param>
        /// <returns></returns>
        public async Task <IEnumerable <Technology> > GetSkilByCategoryAsync(PersonCategory personCategory)
        {
            using (var conn = OpenDBConnection())
            {
                StringBuilder sql = new StringBuilder();
                sql.Length = 0;
                sql.Append("SELECT TE.Id, TE.Name, TE.CategoryId, CA.Id, Ca.Name       ");
                sql.Append("FROM Technology AS TE                                      ");
                sql.Append("INNER JOIN PersonTechnology AS PT                          ");
                sql.Append("ON TE.Id = PT.TechnologyId                                 ");
                sql.Append("INNER JOIN Category AS CA                                  ");
                sql.Append("ON CA.Id = Te.CategoryId                                   ");
                sql.Append("WHERE PT.PersonId = @PersonId                              ");
                sql.Append("AND TE.CategoryId = @CategoryId                            ");
                sql.Append("AND TE.Status = 1 AND PT.Status = 1                        ");
                sql.Append("GROUP BY TE.Id, TE.Name, TE.CategoryId, CA.Id, Ca.Name     ");
                var lookup = new Dictionary <int, Technology>();
                var param  = new
                {
                    PersonId   = personCategory.PersonId,
                    CategoryId = personCategory.CategoryId,
                };
                await conn.QueryAsync <Technology, Category, Technology>(sql.ToString(), (m, n) =>
                {
                    Technology mode = new Technology();
                    if (!lookup.TryGetValue(m.Id, out mode))
                    {
                        lookup.Add(m.Id, mode = m);
                    }
                    if (mode.Category == null)
                    {
                        mode.Category = new Category();
                    }
                    mode.Category = n;
                    return(mode);
                }, param);

                var models = lookup.Values.ToList();
                return(models);
            }
        }
 /// <summary>
 /// Check PersonCategory On Delete
 /// </summary>
 /// <param name="personCategory"></param>
 /// <returns></returns>
 public async Task <PersonCategory> CheckPersonCategoryOnDeleteAsync(PersonCategory personCategory)
 {
     using (var conn = OpenDBConnection())
     {
         StringBuilder sql = new StringBuilder();
         sql.Length = 0;
         sql.Append("SELECT PC.*                                   ");
         sql.Append("FROM PersonCategory AS PC                     ");
         sql.Append("INNER JOIN Category AS CA                     ");
         sql.Append("ON PC.CategoryId = CA.Id                      ");
         sql.Append("WHERE PersonId = @PersonId                    ");
         sql.Append("AND CategoryId = @CategoryId                  ");
         sql.Append("AND PC.Status = 0 AND CA.Status = 1           ");
         var param = new
         {
             PersonId   = personCategory.PersonId,
             CategoryId = personCategory.CategoryId
         };
         return(await conn.QueryFirstOrDefaultAsync <PersonCategory>(sql.ToString(), param));
     }
 }
Exemple #14
0
        /// <summary>
        /// Get PersonCategory
        /// </summary>
        /// <param name="skillRequestModel"></param>
        /// <returns></returns>
        public async Task <PersonCategory> GetPersonCategory(SkillRequestModel skillRequestModel)
        {
            int numberItemPersonCategory = await _skillRepository.GetNumberItemPersonCategory();

            int orderIndex = 1;

            if (numberItemPersonCategory > 0)
            {
                orderIndex = await _skillRepository.GetMaxOrderIndex() + 1;
            }
            PersonCategory personCategory = new PersonCategory
            {
                PersonId   = skillRequestModel.PersonId,
                CategoryId = skillRequestModel.CategoryId,
                OrderIndex = orderIndex,
                CreatedBy  = WebAPI.Helpers.HttpContext.CurrentUser,
                UpdatedBy  = WebAPI.Helpers.HttpContext.CurrentUser
            };

            return(personCategory);
        }
        /// <summary>
        /// Check number person category
        /// </summary>
        /// <param name="personCategory"></param>
        /// <returns></returns>
        public async Task <bool> CheckNumberTechnology(PersonCategory personCategory)
        {
            using (var conn = OpenDBConnection())
            {
                StringBuilder sql = new StringBuilder();
                sql.Length = 0;
                sql.Append("SELECT COUNT(PT.Id)                                  ");
                sql.Append("FROM PersonTechnology AS PT                          ");
                sql.Append("INNER JOIN Technology AS TE                          ");
                sql.Append("ON PT.TechnologyId = TE.Id                           ");
                sql.Append("WHERE PT.Status = 1 AND TE.Status = 1                ");
                sql.Append("AND TE.CategoryId = @CategoryId                      ");
                sql.Append("AND PT.PersonId = @PersonId                          ");
                var param = new
                {
                    CategoryId = personCategory.CategoryId,
                    PersonId   = personCategory.PersonId
                };
                var result = await conn.ExecuteScalarAsync <int>(sql.ToString(), param);

                return(result > 0);
            }
        }
Exemple #16
0
        private Person GetOrCreatePerson(string name, string code, PersonCategory category, PersonType type)
        {
            var person = _db.People.SingleOrDefault(p => p.Name == name && p.Code == code);
            if (person == null)
            {
                person = new Person
                {
                    Name = name,
                    Type = type,
                    Category = category,
                    Code = code
                };
                _db.People.Add(person);
                _db.SaveChanges();
            }

            return person;
        }
 public void SetMemberOfCategory(PersonCategory memberOfCategory)
 {
     SetToWhat(memberOfCategory);
 }
Exemple #18
0
        public int GetAdvancedSearchPersonCountByImperativeRequest(PersonSearchProxy proxy, ImperativeRequestLoadState IRLS, ImperativeRequest imperativeRequest, decimal userId, decimal managerId, PersonCategory searchCat)
        {
            {
                const string PersonDetailAlias = "prsDtl";
                const string WorkGroupAlias    = "wg";
                const string RuleGroupAlias    = "rg";
                const string CalculationDateRangeGroupAlias = "cdrg";
                const string DepartmentAlias       = "dep";
                const string OrganizationUnitAlias = "organ";


                ICriteria crit        = base.NHibernateSession.CreateCriteria(typeof(Person));
                Junction  disjunction = Restrictions.Disjunction();
                crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonDetail), PersonDetailAlias);
                crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().IsDeleted), false));

                //فعال
                if (proxy.PersonActivateState != null)
                {
                    crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Active), (bool)proxy.PersonActivateState));
                }

                //کد پرسنلی
                if (!Utility.Utility.IsEmpty(proxy.PersonCode))
                {
                    crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().BarCode), proxy.PersonCode, MatchMode.Anywhere));
                }

                //نام
                if (!Utility.Utility.IsEmpty(proxy.FirstName))
                {
                    crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().FirstName), proxy.FirstName, MatchMode.Anywhere));
                }

                //نام خانوادگی
                if (!Utility.Utility.IsEmpty(proxy.LastName))
                {
                    crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().LastName), proxy.LastName, MatchMode.Anywhere));
                }

                //نام پدر
                if (!Utility.Utility.IsEmpty(proxy.FatherName))
                {
                    crit.Add(Restrictions.Like(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().FatherName), proxy.FatherName, MatchMode.Anywhere));
                }

                //جنسیت
                if (!Utility.Utility.IsEmpty(proxy.Sex))
                {
                    crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Sex), proxy.Sex));
                }

                //شروع تاریخ تولد
                if (!Utility.Utility.IsEmpty(proxy.FromBirthDate))
                {
                    crit.Add(Restrictions.Ge(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().BirthDate), proxy.FromBirthDate));
                }

                //پایان تاریخ تولد
                if (!Utility.Utility.IsEmpty(proxy.ToBirthDate))
                {
                    crit.Add(Restrictions.Le(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().BirthDate), proxy.ToBirthDate));
                }

                //شروع تاریخ استخدام
                if (!Utility.Utility.IsEmpty(proxy.FromEmploymentDate))
                {
                    crit.Add(Restrictions.Ge(Utility.Utility.GetPropertyName(() => new Person().EmploymentDate), proxy.FromEmploymentDate));
                }

                //پایان تاریخ استخدام
                if (!Utility.Utility.IsEmpty(proxy.ToEmploymentDate))
                {
                    crit.Add(Restrictions.Ge(Utility.Utility.GetPropertyName(() => new Person().EndEmploymentDate), proxy.ToEmploymentDate));
                }

                //شماره کارت
                if (!Utility.Utility.IsEmpty(proxy.CartNumber))
                {
                    crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().CardNum), proxy.CartNumber));
                }

                //نظام وضیفه
                if (!Utility.Utility.IsEmpty(proxy.Military))
                {
                    crit.Add(Restrictions.Eq(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().MilitaryStatus), proxy.Military));
                }

                //تحصیلات
                if (!Utility.Utility.IsEmpty(proxy.Education))
                {
                    crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().Education), proxy.Education, MatchMode.Anywhere));
                }

                //تاهل
                if (!Utility.Utility.IsEmpty(proxy.MaritalStatus))
                {
                    crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().MaritalStatus), proxy.MaritalStatus));
                }

                //بخش
                if (!Utility.Utility.IsEmpty(proxy.DepartmentId))
                {
                    crit.CreateAlias("department", DepartmentAlias);

                    if (proxy.IncludeSubDepartments)
                    {
                        disjunction.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Department).ToLower(), new Department()
                        {
                            ID = (decimal)proxy.DepartmentId
                        }));
                        disjunction.Add(Restrictions.Like(DepartmentAlias + "." + Utility.Utility.GetPropertyName(() => new Department().ParentPath), "," + proxy.DepartmentId.ToString() + ",", MatchMode.Anywhere));
                    }
                    else
                    {
                        crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Department).ToLower(), new Department()
                        {
                            ID = (decimal)proxy.DepartmentId
                        }));
                    }
                }

                //پست سازمانی
                if (!Utility.Utility.IsEmpty(proxy.OrganizationUnitId))
                {
                    crit.CreateAlias("OrganizationUnitList", OrganizationUnitAlias);
                    crit.Add(Restrictions.Eq(OrganizationUnitAlias + "." + Utility.Utility.GetPropertyName(() => new OrganizationUnit().ID), (decimal)proxy.OrganizationUnitId));
                }

                //گروه کاری
                if (!Utility.Utility.IsEmpty(proxy.WorkGroupId))
                {
                    crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonWorkGroupList), WorkGroupAlias);
                    crit.Add(Restrictions.Eq(WorkGroupAlias + "." + Utility.Utility.GetPropertyName(() => new AssignWorkGroup().WorkGroup), new WorkGroup()
                    {
                        ID = (decimal)proxy.WorkGroupId
                    }));

                    if (!Utility.Utility.IsEmpty(proxy.WorkGroupFromDate))
                    {
                        crit.Add(Restrictions.Le(WorkGroupAlias + "." + Utility.Utility.GetPropertyName(() => new AssignWorkGroup().FromDate), proxy.WorkGroupFromDate));
                    }
                }

                //گروه قوانین
                if (!Utility.Utility.IsEmpty(proxy.RuleGroupId))
                {
                    crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonRuleCatAssignList), RuleGroupAlias);
                    crit.Add(Restrictions.Eq(RuleGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRuleCatAssignment().RuleCategory), new RuleCategory()
                    {
                        ID = (decimal)proxy.RuleGroupId
                    }));

                    if (!Utility.Utility.IsEmpty(proxy.RuleGroupFromDate))
                    {
                        crit.Add(Restrictions.Le(RuleGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRuleCatAssignment().FromDate), proxy.RuleGroupFromDate));
                    }
                    if (!Utility.Utility.IsEmpty(proxy.RuleGroupToDate))
                    {
                        crit.Add(Restrictions.Ge(RuleGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRuleCatAssignment().ToDate), proxy.RuleGroupToDate));
                    }
                }

                //محدوده محاسبات
                if (!Utility.Utility.IsEmpty(proxy.CalculationDateRangeId))
                {
                    crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonRangeAssignList), CalculationDateRangeGroupAlias);
                    crit.Add(Restrictions.Eq(CalculationDateRangeGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRangeAssignment().CalcDateRangeGroup), new CalculationRangeGroup()
                    {
                        ID = (decimal)proxy.CalculationDateRangeId
                    }));

                    if (!Utility.Utility.IsEmpty(proxy.CalculationFromDate))
                    {
                        crit.Add(Restrictions.Le(CalculationDateRangeGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRangeAssignment().FromDate), proxy.CalculationFromDate));
                    }
                }

                //ایستگاه کنترل
                if (!Utility.Utility.IsEmpty(proxy.ControlStationId))
                {
                    crit.Add(Restrictions.Eq("controlStation", new ControlStation()
                    {
                        ID = (decimal)proxy.ControlStationId
                    }));
                }

                //نوع استخدام
                if (!Utility.Utility.IsEmpty(proxy.EmploymentType))
                {
                    crit.Add(Restrictions.Eq("employmentType", new EmploymentType()
                    {
                        ID = (decimal)proxy.EmploymentType
                    }));
                }

                //جستجو در بین مدیران و اپراتورها
                if (proxy.SearchInCategory != PersonCategory.Public &&
                    !Utility.Utility.IsEmpty(proxy.SearchInCategory))
                {
                    if (proxy.SearchInCategory == PersonCategory.Manager)
                    {
                        IList <Person> personList = new ManagerRepository(false).GetAllManager();
                        var            ids        = from person in personList
                                                    select person.ID;
                        IList <decimal> idList = ids.ToList <decimal>();

                        crit.Add(Restrictions.In(Utility.Utility.GetPropertyName(() => new Person().ID), idList.ToArray()));
                    }
                }
                crit.Add(Expression.Sql(" prs_Id in (select * from fn_GetAccessiblePersons(?,?,?))", new object[] { managerId, userId, (int)searchCat }, new IType[] { NHibernateUtil.Decimal, NHibernateUtil.Decimal, NHibernateUtil.Int32 }));
                if (!disjunction.ToString().Equals("()"))
                {
                    crit.Add(disjunction);
                }
                if (IRLS == ImperativeRequestLoadState.Applied || IRLS == ImperativeRequestLoadState.NotApplied)
                {
                    IList <decimal> ImperativeRequestIDsList = this.NHibernateSession.QueryOver <ImperativeRequest>()
                                                               .Where(impReq => impReq.Precard.ID == imperativeRequest.Precard.ID && impReq.IsLocked && impReq.Year == imperativeRequest.Year && impReq.Month == imperativeRequest.Month)
                                                               .Select(impReq => impReq.ID)
                                                               .List <decimal>();
                    if (imperativeRequest.IsLocked)
                    {
                        crit.Add(Restrictions.In(Utility.Utility.GetPropertyName(() => new Person().ID), ImperativeRequestIDsList.ToArray()));
                    }
                    else
                    {
                        crit.Add(Restrictions.Not(Restrictions.In(Utility.Utility.GetPropertyName(() => new Person().ID), ImperativeRequestIDsList.ToArray())));
                    }
                }
                crit.SetProjection(Projections.Count(Utility.Utility.GetPropertyName(() => new Person().ID)));
                if (!Utility.Utility.IsEmpty(crit.ToString()))
                {
                    object count = crit.UniqueResult();
                    return((int)count);
                }
                return(0);
            }
        }
Exemple #19
0
        /// <summary>
        /// Update Skill
        /// </summary>
        /// <param name="id"></param>
        /// <param name="skillRequestModel"></param>
        /// <returns></returns>
        public async Task <SkillViewModel> UpdateSkill(int id, SkillRequestModel skillRequestModel)
        {
            model.AppResult.Result  = false;
            model.SkillRequestModel = skillRequestModel;
            if (id <= 0)
            {
                model.AppResult.Message = "PersonId not exist!";
            }
            else if (skillRequestModel.TechnologyId.Count <= 0)
            {
                model.AppResult.Message = "TechnologyId not exist!";
            }
            else if (skillRequestModel.CategoryId <= 0)
            {
                model.AppResult.Message = "CategoryId not exist!";
            }
            else
            {
                PersonCategory personCategory = await _skillRepository.GetPersonCategoryAsync(id, null, null);

                if (personCategory == null)
                {
                    model.AppResult.Message = "Update failure, Skill not exists";
                }
                else
                {
                    var modelCategory = await _categoryRepository.FindAsync(skillRequestModel.CategoryId);

                    if (modelCategory == null)
                    {
                        model.AppResult.Message = "Update failure, Category not exists";
                    }
                    else
                    {
                        List <PersonTechnology> personTechnologies = new List <PersonTechnology>();
                        personTechnologies = await GetListPersonTechnology(skillRequestModel);

                        if (personTechnologies.Count > 0)
                        {
                            personCategory.CategoryId = skillRequestModel.CategoryId;
                            personCategory.CreatedBy  = WebAPI.Helpers.HttpContext.CurrentUser;
                            personCategory.UpdatedBy  = WebAPI.Helpers.HttpContext.CurrentUser;
                            await _skillRepository.DeletePersonTechnologyToUpdateAsync(personCategory);

                            await _skillRepository.InsertListPersonTechnologyAsync(personTechnologies);

                            if (id > 0 && skillRequestModel.PersonId > 0)
                            {
                                List <Category> listResult = new List <Category>();
                                modelCategory = await _skillRepository.GetSkillInsertAsync(id, skillRequestModel.PersonId);

                                if (modelCategory != null)
                                {
                                    model.AppResult.Result  = true;
                                    model.AppResult.Message = Constants.Constant.UPDATE_SUCCESS;
                                    listResult.Add(modelCategory);
                                    model.AppResult.DataResult = GetListSkillResource(listResult).FirstOrDefault();
                                }
                            }
                        }
                        else
                        {
                            model.AppResult.Message = "Update failure, Technology not exists";
                        }
                    }
                }
            }
            return(model);
        }
Exemple #20
0
        /// <summary>
        /// Inser Skill
        /// </summary>
        /// <param name="skillRequestModel"></param>
        /// <returns></returns>
        public async Task <SkillViewModel> InserSkill(SkillRequestModel skillRequestModel)
        {
            model.AppResult.Result = false;
            if (skillRequestModel.PersonId <= 0)
            {
                model.AppResult.Message = "PersonId not exist!";
            }
            else if (skillRequestModel.CategoryId <= 0)
            {
                model.AppResult.Message = "CategoryId not exist!";
            }
            else if (skillRequestModel.TechnologyId.Count <= 0)
            {
                model.AppResult.Message = "TechnologyId not exist!";
            }
            else
            {
                model.SkillRequestModel = skillRequestModel;
                PersonCategory personCategory = await GetPersonCategory(skillRequestModel);

                List <PersonTechnology> personTechnologies = await GetListPersonTechnology(skillRequestModel);

                Category modelCategory    = new Category();
                int      idPersonCategory = 0;
                int      idPerson         = 0;
                modelCategory = await _categoryRepository.FindAsync(personCategory.CategoryId);

                if (modelCategory == null)
                {
                    model.AppResult.Message = "Create failure, Category not exists";
                }
                else
                {
                    if (personTechnologies.Count > 0)
                    {
                        if (await _skillRepository.CheckPersonCategoryAsync(personCategory))
                        {
                            if (await _skillRepository.CheckNumberTechnology(personCategory))
                            {
                                model.AppResult.Message = "Create failure, Skill already exists";
                                return(model);
                            }
                            else
                            {
                                personCategory.OrderIndex = await _skillRepository.GetMaxOrderIndex() + 1;

                                personCategory.UpdatedAt = DateTime.Now;
                                var resultNumberCategory = await _skillRepository.UpdatePersonCategoryToInsertAsync(personCategory);

                                if (resultNumberCategory > 0)
                                {
                                    idPerson         = personCategory.PersonId;
                                    idPersonCategory = (await _skillRepository.GetPersonCategoryAsync(null, personCategory.PersonId, personCategory.CategoryId)).Id;
                                    var resultNumberTechnology = await InsertListPersonTechnology(personTechnologies);

                                    if (resultNumberTechnology <= 0)
                                    {
                                        model.AppResult.Message = "Create failure, Technology not exists";
                                    }
                                }
                                else
                                {
                                    model.AppResult.Message = "Create failure, Category not exists";
                                }
                            }
                        }
                        else
                        {
                            PersonCategory modelPersonCategory = await _skillRepository.CheckPersonCategoryOnDeleteAsync(personCategory);

                            if (modelPersonCategory == null)
                            {
                                idPersonCategory = await _skillRepository.InsertPersonCategoryAsync(personCategory);

                                idPerson = skillRequestModel.PersonId;
                            }
                            else
                            {
                                modelPersonCategory.OrderIndex = await _skillRepository.GetMaxOrderIndex() + 1;

                                modelPersonCategory.UpdatedAt = DateTime.Now;
                                var resultNumberCategor = await _skillRepository.UpdatePersonCategoryToInsertAsync(modelPersonCategory);

                                if (resultNumberCategor > 0)
                                {
                                    idPersonCategory = modelPersonCategory.Id;
                                    idPerson         = modelPersonCategory.PersonId;
                                }
                                else
                                {
                                    model.AppResult.Message = "Create failure, Category not exists";
                                }
                            }
                            var resultNumberTechnology = await InsertListPersonTechnology(personTechnologies);

                            if (resultNumberTechnology <= 0)
                            {
                                model.AppResult.Message = "Create failure, Technology not exists";
                            }
                        }
                        if (idPersonCategory > 0 && idPerson > 0)
                        {
                            List <Category> listResult = new List <Category>();
                            modelCategory = await _skillRepository.GetSkillInsertAsync(idPersonCategory, idPerson);

                            if (modelCategory != null)
                            {
                                model.AppResult.Result  = true;
                                model.AppResult.Message = Constants.Constant.INSERT_SUCCESS;
                                listResult.Add(modelCategory);
                                model.AppResult.DataResult = GetListSkillResource(listResult).FirstOrDefault();
                            }
                        }
                    }
                    else
                    {
                        model.AppResult.Message = "Create failure, Technology not exists";
                    }
                }
            }
            return(model);
        }
Exemple #21
0
        public int GetQuickSearchPersonCountByImperativeRequest(string key, ImperativeRequestLoadState IRLS, ImperativeRequest imperativeRequest, decimal userId, decimal managerId, PersonCategory searchCat)
        {
            string SQLCommand = "";

            SQLCommand = @"select count(prs_ID) from TA_Person prs
                                  where Prs_IsDeleted=0  AND prs_Active=1 AND 
                                        (prs_BarCode like :searchKey OR
                                        prs_CardNum like :searchKey OR
                                        prs_FirstName + ' ' + prs_LastName like :searchKey)
                                        AND prs.prs_BarCode <> '00000000'
                                        AND prs.prs_ID in (select * from fn_GetAccessiblePersons(:managerId,:userId,:searchCat))";

            if (IRLS != ImperativeRequestLoadState.Normal)
            {
                SQLCommand += "AND prs_ID";
                switch (IRLS)
                {
                case ImperativeRequestLoadState.Applied:
                    SQLCommand += " in";
                    break;

                case ImperativeRequestLoadState.NotApplied:
                    SQLCommand += " not in";
                    break;
                }
                SQLCommand += @"(select impReq.imperativeRequest_PersonID from TA_ImperativeRequest impReq 
                             where impReq.imperativeRequest_PrecardID = :precardId
                             and impReq.imperativeRequest_IsLocked = :isLocked 
                             and impReq.imperativeRequest_Year = :year 
                             and impReq.imperativeRequest_Month = :month
                            )";
            }

            IQuery query = base.NHibernateSession.CreateSQLQuery(SQLCommand)
                           .SetParameter("searchKey", "%" + key + "%")
                           .SetParameter("userId", userId)
                           .SetParameter("managerId", managerId)
                           .SetParameter("searchCat", (int)searchCat);

            if (IRLS == ImperativeRequestLoadState.Applied || IRLS == ImperativeRequestLoadState.NotApplied)
            {
                query = query.SetParameter("precardId", imperativeRequest.Precard.ID)
                        .SetParameter("isLocked", imperativeRequest.IsLocked)
                        .SetParameter("year", imperativeRequest.Year)
                        .SetParameter("month", imperativeRequest.Month);
            }
            object count = query.List <object>().First();

            return(Utility.Utility.ToInteger(count.ToString()));
        }
Exemple #22
0
        public IList <Person> GetQuickSearchPersonByImperativeRequest(string key, ImperativeRequestLoadState IRLS, ImperativeRequest imperativeRequest, decimal userId, decimal managerId, PersonCategory searchCat, int pageSize, int pageIndex)
        {
            string SQLCommand = "";

            SQLCommand = @"SELECT prs.* FROM TA_Person as prs
                                  where prs_IsDeleted=0 AND prs_Active=1 AND prs_BarCode <> '00000000' 
                                        AND ( prs_BarCode like :searchKey OR
                                        prs_CardNum like :searchKey OR
                                        prs_FirstName + ' ' + prs_LastName like :searchKey)
                                        AND prs_ID in (select * from fn_GetAccessiblePersons(:managerId,:userId,:searchCat))";

            if (IRLS != ImperativeRequestLoadState.Normal)
            {
                SQLCommand += "AND prs_ID";
                switch (IRLS)
                {
                case ImperativeRequestLoadState.Applied:
                    SQLCommand += " in";
                    break;

                case ImperativeRequestLoadState.NotApplied:
                    SQLCommand += " not in";
                    break;
                }
                SQLCommand += @"(select impReq.imperativeRequest_PersonID from TA_ImperativeRequest impReq 
                             where impReq.imperativeRequest_PrecardID = :precardId
                             and impReq.imperativeRequest_IsLocked = :isLocked 
                             and impReq.imperativeRequest_Year = :year 
                             and impReq.imperativeRequest_Month = :month
                            )";
            }

            IQuery query = base.NHibernateSession.CreateSQLQuery(SQLCommand)
                           .AddEntity(typeof(Person))
                           .SetParameter("searchKey", "%" + key + "%")
                           .SetParameter("userId", userId)
                           .SetParameter("managerId", managerId)
                           .SetParameter("searchCat", (int)searchCat);

            if (IRLS == ImperativeRequestLoadState.Applied || IRLS == ImperativeRequestLoadState.NotApplied)
            {
                query = query.SetParameter("precardId", imperativeRequest.Precard.ID)
                        .SetParameter("isLocked", imperativeRequest.IsLocked)
                        .SetParameter("year", imperativeRequest.Year)
                        .SetParameter("month", imperativeRequest.Month);
            }
            query = query.SetFirstResult(pageIndex * pageSize).SetMaxResults(pageSize);

            IList <Person> list = new List <Person>();

            list = query.List <Person>();

            return(list);
        }
        public int GetAdvancedSearchPersonCountByImperativeRequest(PersonAdvanceSearchProxy proxy, ImperativeRequestLoadState IRLS, ImperativeRequest imperativeRequest, PersonCategory searchInCategory)
        {
            try
            {
                BApplicationSettings.CheckGTSLicense();

                #region Date Convert
                if (!Utility.IsEmpty(proxy.FromBirthDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                {
                    proxy.FromBirthDate = Utility.ToMildiDateString(proxy.FromBirthDate);
                }
                if (!Utility.IsEmpty(proxy.ToBirthDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                {
                    proxy.ToBirthDate = Utility.ToMildiDateString(proxy.ToBirthDate);
                }
                if (!Utility.IsEmpty(proxy.FromEmploymentDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                {
                    proxy.FromEmploymentDate = Utility.ToMildiDateString(proxy.FromEmploymentDate);
                }
                if (!Utility.IsEmpty(proxy.ToEmploymentDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                {
                    proxy.ToEmploymentDate = Utility.ToMildiDateString(proxy.ToEmploymentDate);
                }
                if (!Utility.IsEmpty(proxy.WorkGroupFromDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                {
                    proxy.WorkGroupFromDate = Utility.ToMildiDateString(proxy.WorkGroupFromDate);
                }
                if (!Utility.IsEmpty(proxy.RuleGroupFromDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                {
                    proxy.RuleGroupFromDate = Utility.ToMildiDateString(proxy.RuleGroupFromDate);
                }
                if (!Utility.IsEmpty(proxy.RuleGroupToDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                {
                    proxy.RuleGroupToDate = Utility.ToMildiDateString(proxy.RuleGroupToDate);
                }
                if (!Utility.IsEmpty(proxy.CalculationFromDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                {
                    proxy.CalculationFromDate = Utility.ToMildiDateString(proxy.CalculationFromDate);
                }
                #endregion

                decimal managerId = this.personBusiness.GetCurentManagerId(ref searchInCategory);
                int     count     = this.imperativeRequestRepository.GetAdvancedSearchPersonCountByImperativeRequest(proxy, IRLS, imperativeRequest, BUser.CurrentUser.ID, managerId, searchInCategory);
                return(count);
            }
            catch (Exception ex)
            {
                LogException(ex, "BImperativeRequest", "GetAdvancedSearchPersonCountByImperativeRequest");
                throw ex;
            }
        }
        public IList <ImperativeUndermanagementInfoProxy> GetQuickSearchPersonByImperativeRequest(string searchValue, ImperativeRequestLoadState IRLS, ImperativeRequest imperativeRequest, PersonCategory searchInCategory, int pageIndex, int pageSize)
        {
            try
            {
                UIValidationExceptions exception = new UIValidationExceptions();
                if (imperativeRequest.Precard == null || imperativeRequest.Precard.ID == 0)
                {
                    exception.Add(new ValidationException(ExceptionResourceKeys.RequestPrecardIsEmpty, "پیشکارت نباید خالی باشد", ExceptionSrc));
                }
                if (imperativeRequest.Year == null || imperativeRequest.Year == 0)
                {
                    exception.Add(new ValidationException(ExceptionResourceKeys.RequestYearIsEmpty, "سال نباید خالی باشد", ExceptionSrc));
                }
                if (imperativeRequest.Month == null || imperativeRequest.Month == 0)
                {
                    exception.Add(new ValidationException(ExceptionResourceKeys.RequestMonthIsEmpty, "ماه نباید خالی باشد", ExceptionSrc));
                }

                if (exception.Count == 0)
                {
                    BApplicationSettings.CheckGTSLicense();

                    IList <Person> personList = new List <Person>();
                    ISearchPerson  searchTool = new BPerson();
                    searchValue = searchValue == null ? String.Empty : searchValue;
                    searchValue = searchValue.Trim();
                    int count = searchTool.GetPersonInQuickSearchCount(searchValue, searchInCategory);
                    if (pageSize * pageIndex == 0 || pageSize * pageIndex < count)
                    {
                        decimal        managerId = this.personBusiness.GetCurentManagerId(ref searchInCategory);
                        IList <Person> result    = this.imperativeRequestRepository.GetQuickSearchPersonByImperativeRequest(searchValue, IRLS, imperativeRequest, BUser.CurrentUser.ID, managerId, searchInCategory, pageSize, pageIndex);
                        return(this.ConvertToImperativeUndermanagementInfoProxy(result, imperativeRequest, pageSize, pageIndex));
                    }
                    else
                    {
                        throw new OutOfExpectedRangeException("0", Convert.ToString(count - 1), Convert.ToString(pageSize * (pageIndex + 1)), ExceptionSrc + "GetQuickSearchPersonByImperativeRequest");
                    }
                }
                else
                {
                    throw exception;
                }
            }
            catch (Exception ex)
            {
                LogException(ex, "BImperativeRequest", "GetQuickSearchPersonByImperativeRequest");
                throw ex;
            }
        }
        public int GetQuickSearchPersonCountByImperativeRequest(string key, ImperativeRequestLoadState IRLS, ImperativeRequest imperativeRequest, PersonCategory searchCat)
        {
            try
            {
                BApplicationSettings.CheckGTSLicense();

                IList <Person> personList = new List <Person>();

                key = key == null ? String.Empty : key;
                key = key.Trim();
                decimal managerId = this.personBusiness.GetCurentManagerId(ref searchCat);
                int     count     = this.imperativeRequestRepository.GetQuickSearchPersonCountByImperativeRequest(key, IRLS, imperativeRequest, BUser.CurrentUser.ID, managerId, searchCat);
                return(count);
            }
            catch (Exception ex)
            {
                LogException(ex, "BImperativeRequest", "GetQuickSearchPersonCountByImperativeRequest");
                throw ex;
            }
        }
        public IList <ImperativeUndermanagementInfoProxy> GetAdvancedSearchPersonByImperativeRequest(PersonAdvanceSearchProxy proxy, ImperativeRequestLoadState IRLS, ImperativeRequest imperativeRequest, PersonCategory searchInCategory, int pageIndex, int pageSize)
        {
            try
            {
                UIValidationExceptions exception = new UIValidationExceptions();
                if (imperativeRequest.Precard == null || imperativeRequest.Precard.ID == 0)
                {
                    exception.Add(new ValidationException(ExceptionResourceKeys.RequestPrecardIsEmpty, "پیشکارت نباید خالی باشد", ExceptionSrc));
                }
                if (imperativeRequest.Year == null || imperativeRequest.Year == 0)
                {
                    exception.Add(new ValidationException(ExceptionResourceKeys.RequestYearIsEmpty, "سال نباید خالی باشد", ExceptionSrc));
                }
                if (imperativeRequest.Month == null || imperativeRequest.Month == 0)
                {
                    exception.Add(new ValidationException(ExceptionResourceKeys.RequestMonthIsEmpty, "ماه نباید خالی باشد", ExceptionSrc));
                }

                if (exception.Count == 0)
                {
                    BApplicationSettings.CheckGTSLicense();

                    #region Date Convert
                    if (!Utility.IsEmpty(proxy.FromBirthDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                    {
                        proxy.FromBirthDate = Utility.ToMildiDateString(proxy.FromBirthDate);
                    }
                    if (!Utility.IsEmpty(proxy.ToBirthDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                    {
                        proxy.ToBirthDate = Utility.ToMildiDateString(proxy.ToBirthDate);
                    }
                    if (!Utility.IsEmpty(proxy.FromEmploymentDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                    {
                        proxy.FromEmploymentDate = Utility.ToMildiDateString(proxy.FromEmploymentDate);
                    }
                    if (!Utility.IsEmpty(proxy.ToEmploymentDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                    {
                        proxy.ToEmploymentDate = Utility.ToMildiDateString(proxy.ToEmploymentDate);
                    }
                    if (!Utility.IsEmpty(proxy.WorkGroupFromDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                    {
                        proxy.WorkGroupFromDate = Utility.ToMildiDateString(proxy.WorkGroupFromDate);
                    }
                    if (!Utility.IsEmpty(proxy.RuleGroupFromDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                    {
                        proxy.RuleGroupFromDate = Utility.ToMildiDateString(proxy.RuleGroupFromDate);
                    }
                    if (!Utility.IsEmpty(proxy.RuleGroupToDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                    {
                        proxy.RuleGroupToDate = Utility.ToMildiDateString(proxy.RuleGroupToDate);
                    }
                    if (!Utility.IsEmpty(proxy.CalculationFromDate) && BLanguage.CurrentSystemLanguage == LanguagesName.Parsi)
                    {
                        proxy.CalculationFromDate = Utility.ToMildiDateString(proxy.CalculationFromDate);
                    }
                    #endregion

                    IList <Person> list;
                    if (!Utility.IsEmpty(proxy.PersonId))
                    {
                        list = new List <Person>();
                        Person prs = this.personBusiness.GetByID((decimal)proxy.PersonId);
                        list.Add(prs);
                    }
                    else
                    {
                        decimal managerId = personBusiness.GetCurentManagerId(ref searchInCategory);
                        list = this.imperativeRequestRepository.GetAdvancedSearchPersonByImperativeRequest(proxy, IRLS, imperativeRequest, BUser.CurrentUser.ID, managerId, searchInCategory, pageIndex, pageSize);
                    }
                    return(this.ConvertToImperativeUndermanagementInfoProxy(list, imperativeRequest, pageSize, pageIndex));
                }
                else
                {
                    throw exception;
                }
            }
            catch (Exception ex)
            {
                LogException(ex, "BImperativeRequest", "GetAdvancedSearchPersonByImperativeRequest");
                throw ex;
            }
        }
Exemple #27
0
 public bool Update(PersonCategory category)
 {
     return(_service.Update(category));
 }
Exemple #28
0
 public bool Insert(PersonCategory category)
 {
     return(_service.Insert(category));
 }
Exemple #29
0
        public IList <Person> GetAdvancedSearchPersonByImperativeRequest(PersonSearchProxy proxy, ImperativeRequestLoadState IRLS, ImperativeRequest imperativeRequest, decimal userId, decimal managerId, PersonCategory searchCat, int pageIndex, int pageSize)
        {
            const string PersonDetailAlias = "prsDtl";
            const string WorkGroupAlias    = "wg";
            const string RuleGroupAlias    = "rg";
            const string CalculationDateRangeGroupAlias = "cdrg";
            const string DepartmentAlias       = "dep";
            const string OrganizationUnitAlias = "organ";
            const string PersonTASpecAlias     = "prsTs";
            const string ContractAlias         = "con";
            const string GradeAlias            = "grade";
            const string EmploymentAlias       = "emp";
            ICriteria    crit        = base.NHibernateSession.CreateCriteria(typeof(Person));
            Junction     disjunction = Restrictions.Disjunction();

            crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().IsDeleted), false));
            crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonDetailList), PersonDetailAlias);

            //فعال
            if (proxy.PersonActivateState != null)
            {
                crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Active), (bool)proxy.PersonActivateState));
            }

            //کد پرسنلی
            if (!Utility.Utility.IsEmpty(proxy.PersonCode))
            {
                crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().BarCode), proxy.PersonCode, MatchMode.Anywhere));
            }

            //نام
            if (!Utility.Utility.IsEmpty(proxy.FirstName))
            {
                crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().FirstName), proxy.FirstName, MatchMode.Anywhere));
            }

            //نام خانوادگی
            if (!Utility.Utility.IsEmpty(proxy.LastName))
            {
                crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().LastName), proxy.LastName, MatchMode.Anywhere));
            }

            //نام پدر
            if (!Utility.Utility.IsEmpty(proxy.FatherName))
            {
                crit.Add(Restrictions.Like(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().FatherName), proxy.FatherName, MatchMode.Anywhere));
            }

            //جنسیت ,پیش فرض آن از واسط کاربر -1 است
            if (!Utility.Utility.IsEmpty(proxy.Sex) && proxy.Sex >= 0)
            {
                crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Sex), proxy.Sex));
            }

            //شماره کارت
            if (!Utility.Utility.IsEmpty(proxy.CartNumber))
            {
                crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().CardNum), proxy.CartNumber));
            }

            //نظام وضیفه , پیش فرض آن از واسط کاربر 0 است
            if (!Utility.Utility.IsEmpty(proxy.Military) && proxy.Military > 0)
            {
                crit.Add(Restrictions.Eq(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().MilitaryStatus), proxy.Military));
            }

            //تحصیلات
            if (!Utility.Utility.IsEmpty(proxy.Education))
            {
                crit.Add(Restrictions.Like(Utility.Utility.GetPropertyName(() => new Person().Education), proxy.Education, MatchMode.Anywhere));
            }

            //تاهل , پیش فرض آن از واسط کاربر 0 است
            if (!Utility.Utility.IsEmpty(proxy.MaritalStatus) && proxy.MaritalStatus > 0)
            {
                crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().MaritalStatus), proxy.MaritalStatus));
            }

            //شروع تاریخ تولد
            if (!Utility.Utility.IsEmpty(proxy.FromBirthDate))
            {
                crit.Add(Restrictions.Ge(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().BirthDate), proxy.FromBirthDate));
            }

            //پایان تاریخ تولد
            if (!Utility.Utility.IsEmpty(proxy.ToBirthDate))
            {
                crit.Add(Restrictions.Le(PersonDetailAlias + "." + Utility.Utility.GetPropertyName(() => new PersonDetail().BirthDate), proxy.ToBirthDate));
            }

            //شروع تاریخ استخدام
            if (!Utility.Utility.IsEmpty(proxy.FromEmploymentDate))
            {
                crit.Add(Restrictions.Ge(Utility.Utility.GetPropertyName(() => new Person().EmploymentDate), proxy.FromEmploymentDate));
            }

            //پایان تاریخ استخدام
            if (!Utility.Utility.IsEmpty(proxy.ToEmploymentDate))
            {
                crit.Add(Restrictions.Ge(Utility.Utility.GetPropertyName(() => new Person().EndEmploymentDate), proxy.ToEmploymentDate));
            }

            //بخش
            //if (!Utility.Utility.IsEmpty(proxy.DepartmentId))
            //{
            //    crit.CreateAlias("department", DepartmentAlias);

            //    if (proxy.IncludeSubDepartments)
            //    {
            //        disjunction.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Department).ToLower(), new Department() { ID = (decimal)proxy.DepartmentId }));
            //        disjunction.Add(Restrictions.Like(DepartmentAlias + "." + Utility.Utility.GetPropertyName(() => new Department().ParentPath), "," + proxy.DepartmentId.ToString() + ",", MatchMode.Anywhere));

            //    }
            //    else
            //    {
            //        crit.Add(Restrictions.Eq(Utility.Utility.GetPropertyName(() => new Person().Department).ToLower(), new Department() { ID = (decimal)proxy.DepartmentId }));
            //    }

            //}

            if (!Utility.Utility.IsEmpty(proxy.DepartmentListId))
            {
                crit.CreateAlias("department", DepartmentAlias);

                if (proxy.IncludeSubDepartments)
                {
                    disjunction.Add(Restrictions.In(DepartmentAlias + "." + Utility.Utility.GetPropertyName(() => new Department().ID), proxy.DepartmentListId.ToArray()));

                    foreach (decimal item in proxy.DepartmentListId)
                    {
                        disjunction.Add(Restrictions.Like(DepartmentAlias + "." + Utility.Utility.GetPropertyName(() => new Department().ParentPath), "," + item.ToString() + ",", MatchMode.Anywhere));
                    }
                }
                else
                {
                    crit.Add(Restrictions.In(DepartmentAlias + "." + Utility.Utility.GetPropertyName(() => new Department().ID), proxy.DepartmentListId.ToArray()));
                }
            }

            //پست سازمانی
            if (!Utility.Utility.IsEmpty(proxy.OrganizationUnitId))
            {
                crit.CreateAlias("OrganizationUnitList", OrganizationUnitAlias);
                crit.Add(Restrictions.Eq(OrganizationUnitAlias + "." + Utility.Utility.GetPropertyName(() => new OrganizationUnit().ID), (decimal)proxy.OrganizationUnitId));
            }

            //گروه کاری
            if (!Utility.Utility.IsEmpty(proxy.WorkGroupId))
            {
                crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonWorkGroupList), WorkGroupAlias);
                crit.Add(Restrictions.Eq(WorkGroupAlias + "." + Utility.Utility.GetPropertyName(() => new AssignWorkGroup().WorkGroup), new WorkGroup()
                {
                    ID = (decimal)proxy.WorkGroupId
                }));

                if (!Utility.Utility.IsEmpty(proxy.WorkGroupFromDate))
                {
                    crit.Add(Restrictions.Le(WorkGroupAlias + "." + Utility.Utility.GetPropertyName(() => new AssignWorkGroup().FromDate), proxy.WorkGroupFromDate));
                }
            }
            //رتبه
            if (!Utility.Utility.IsEmpty(proxy.GradeId))
            {
                crit.CreateAlias("grade", GradeAlias);
                crit.Add(Restrictions.Eq(GradeAlias + "." + Utility.Utility.GetPropertyName(() => new Grade().ID), (decimal)proxy.GradeId));
            }
            //گروه قوانین
            if (!Utility.Utility.IsEmpty(proxy.RuleGroupId))
            {
                crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonRuleCatAssignList), RuleGroupAlias);
                crit.Add(Restrictions.Eq(RuleGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRuleCatAssignment().RuleCategory), new RuleCategory()
                {
                    ID = (decimal)proxy.RuleGroupId
                }));

                if (!Utility.Utility.IsEmpty(proxy.RuleGroupFromDate))
                {
                    crit.Add(Restrictions.Le(RuleGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRuleCatAssignment().FromDate), proxy.RuleGroupFromDate));
                }
                if (!Utility.Utility.IsEmpty(proxy.RuleGroupToDate))
                {
                    crit.Add(Restrictions.Ge(RuleGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRuleCatAssignment().ToDate), proxy.RuleGroupToDate));
                }
            }

            //محدوده محاسبات
            if (!Utility.Utility.IsEmpty(proxy.CalculationDateRangeId))
            {
                crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonRangeAssignList), CalculationDateRangeGroupAlias);
                crit.Add(Restrictions.Eq(CalculationDateRangeGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRangeAssignment().CalcDateRangeGroup), new CalculationRangeGroup()
                {
                    ID = (decimal)proxy.CalculationDateRangeId
                }));

                if (!Utility.Utility.IsEmpty(proxy.CalculationFromDate))
                {
                    crit.Add(Restrictions.Le(CalculationDateRangeGroupAlias + "." + Utility.Utility.GetPropertyName(() => new PersonRangeAssignment().FromDate), proxy.CalculationFromDate));
                }
            }

            ////ایستگاه کنترل
            //if (!Utility.Utility.IsEmpty(proxy.ControlStationId))
            //{
            //    crit.Add(Restrictions.Eq("controlStation", new ControlStation() { ID = (decimal)proxy.ControlStationId }));
            //}
            if (!Utility.Utility.IsEmpty(proxy.ControlStationListId))
            {
                List <ControlStation> controlStationList = new List <ControlStation>();
                foreach (decimal item in proxy.ControlStationListId)
                {
                    controlStationList.Add(new ControlStation()
                    {
                        ID = item
                    });
                }
                crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonTASpecList), PersonTASpecAlias);
                crit.Add(Restrictions.In(PersonTASpecAlias + "." + Utility.Utility.GetPropertyName(() => new PersonTASpec().ControlStation), controlStationList));
            }
            //نوع استخدام
            //if (!Utility.Utility.IsEmpty(proxy.EmploymentType))
            //{
            //    crit.Add(Restrictions.Eq("employmentType", new EmploymentType() { ID = (decimal)proxy.EmploymentType }));
            //}
            if (!Utility.Utility.IsEmpty(proxy.EmploymentTypeListId))
            {
                crit.CreateAlias("employmentType", EmploymentAlias);
                crit.Add(Restrictions.In(EmploymentAlias + "." + Utility.Utility.GetPropertyName(() => new EmploymentType().ID), proxy.EmploymentTypeListId.ToArray()));
            }
            // گروه واسط کاربری
            if (!Utility.Utility.IsEmpty(proxy.UIValidationGroupListId))
            {
                List <UIValidationGroup> uiValidationGroupList = new List <UIValidationGroup>();
                foreach (decimal item in proxy.UIValidationGroupListId)
                {
                    uiValidationGroupList.Add(new UIValidationGroup()
                    {
                        ID = item
                    });
                }
                crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonTASpecList), PersonTASpecAlias);
                crit.Add(Restrictions.In(PersonTASpecAlias + "." + Utility.Utility.GetPropertyName(() => new PersonTASpec().UIValidationGroup), uiValidationGroupList));
            }
            //قرارداد
            if (!Utility.Utility.IsEmpty(proxy.ContractId))
            {
                crit.CreateAlias(Utility.Utility.GetPropertyName(() => new Person().PersonContractAssignmentList), ContractAlias);
                crit.Add(Restrictions.Eq(ContractAlias + "." + Utility.Utility.GetPropertyName(() => new PersonContractAssignment().Contract), new Contract()
                {
                    ID = (decimal)proxy.ContractId
                }));
                crit.Add(Restrictions.Eq(ContractAlias + "." + Utility.Utility.GetPropertyName(() => new PersonContractAssignment().IsDeleted), false));
                if (!Utility.Utility.IsEmpty(proxy.ContractFromDate))
                {
                    crit.Add(Restrictions.Ge(ContractAlias + "." + Utility.Utility.GetPropertyName(() => new PersonContractAssignment().FromDate), Utility.Utility.ToMildiDateTime(proxy.ContractFromDate)));
                }
                if (!Utility.Utility.IsEmpty(proxy.RuleGroupToDate))
                {
                    crit.Add(Restrictions.Le(ContractAlias + "." + Utility.Utility.GetPropertyName(() => new PersonContractAssignment().ToDate), Utility.Utility.ToMildiDateTime(proxy.ContractToDate)));
                }
            }
            //جستجو در بین مدیران و اپراتورها
            if (proxy.SearchInCategory != PersonCategory.Public &&
                !Utility.Utility.IsEmpty(proxy.SearchInCategory))
            {
                if (proxy.SearchInCategory == PersonCategory.Manager)
                {
                    IList <Person> personList = new ManagerRepository(false).GetAllManager();
                    var            ids        = from person in personList
                                                select person.ID;
                    IList <decimal> idList = ids.ToList <decimal>();

                    crit.Add(Restrictions.In(Utility.Utility.GetPropertyName(() => new Person().ID), idList.ToArray()));
                }
            }
            IList <Person> list = new List <Person>();

            crit.Add(Expression.Sql(" prs_Id in (select * from fn_GetAccessiblePersons(?,?,?))", new object[] { managerId, userId, (int)searchCat }, new IType[] { NHibernateUtil.Decimal, NHibernateUtil.Decimal, NHibernateUtil.Int32 }));

            if (!disjunction.ToString().Equals("()"))
            {
                crit.Add(disjunction);
            }
            if (IRLS == ImperativeRequestLoadState.Applied || IRLS == ImperativeRequestLoadState.NotApplied)
            {
                IList <decimal> ImperativeRequestIDsList = this.NHibernateSession.QueryOver <ImperativeRequest>()
                                                           .Where(impReq => impReq.Precard.ID == imperativeRequest.Precard.ID && impReq.IsLocked && impReq.Year == imperativeRequest.Year && impReq.Month == imperativeRequest.Month)
                                                           .Select(impReq => impReq.ID)
                                                           .List <decimal>();
                if (imperativeRequest.IsLocked)
                {
                    crit.Add(Restrictions.In(Utility.Utility.GetPropertyName(() => new Person().ID), ImperativeRequestIDsList.ToArray()));
                }
                else
                {
                    crit.Add(Restrictions.Not(Restrictions.In(Utility.Utility.GetPropertyName(() => new Person().ID), ImperativeRequestIDsList.ToArray())));
                }
            }
            if (!Utility.Utility.IsEmpty(crit.ToString()))
            {
                if (pageIndex == 0 && pageSize == 0)
                {
                    list = crit
                           .List <Person>();
                }
                else
                {
                    list = crit
                           .SetFirstResult(pageIndex * pageSize)
                           .SetMaxResults(pageSize)
                           .List <Person>();
                }
            }
            return(list);
        }
Exemple #30
0
        private Person GetOrCreatePerson(string name, DateTime birthday, PersonCategory category, PersonType type)
        {
            var person = _db.People.SingleOrDefault(p => p.Name == name && p.Birthday == birthday);

            if (person == null)
            {
                person = new Person
                {
                    Name = name,
                    Birthday = birthday,
                    Type = type,
                    Category = category
                };
                _db.People.Add(person);
                _db.SaveChanges();
            }

            return person;
        }