Ejemplo n.º 1
0
        /// <summary>
        /// 添加标签的方法
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        public int AddTags(List <SkillTag> tags)
        {
            var result = 0;

            foreach (var tag in tags)
            {
                SkillTag match = this.context.SkillTag.Where(r => r.TagName == tag.TagName).FirstOrDefault();
                if (match == null)
                {
                    tag.TagID = Guid.NewGuid().ToString();
                    this.context.SkillTag.Add(tag);
                    this.context.SkillTags.Add(new SkillTags()
                    {
                        PositionID = tag.PositionID, TagID = tag.TagID.ToString(), ID = Guid.NewGuid().ToString()
                    });
                }
                else
                {
                    SkillTags tagMatch = this.context.SkillTags.Where(r => r.TagID == match.TagID && r.PositionID == tag.PositionID).FirstOrDefault();
                    if (tagMatch == null)
                    {
                        this.context.SkillTags.Add(new SkillTags()
                        {
                            PositionID = tag.PositionID, TagID = match.TagID, ID = Guid.NewGuid().ToString()
                        });
                    }
                }
            }
            result = this.context.SaveChanges();
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建调查问卷
        /// </summary>
        /// <param name="survey"></param>
        /// <returns></returns>
        public int Create(SurveyModel survey)
        {
            SurveyContext context = new SurveyContext();

            survey.CreateTime  = DateTime.Now;
            survey.AuditStatus = (int)SurveyStatus.audit;
            //匹配公司信息
            Company match = context.Company.FirstOrDefault(r => r.CompanyNo == survey.CompanyNo);

            if (match != null)
            {
                survey.CompanyID        = match.CompanyID;
                match.City              = survey.Company.City;
                match.CompanyDesc       = survey.Company.CompanyDesc;
                match.CompanyType       = survey.Company.CompanyType;
                match.CompanyDetailType = survey.Company.CompanyDetailType;
                survey.City             = match.City;
                survey.Company          = match;
            }
            else
            {
                survey.City = survey.Company.City;
                survey.Company.CompanyNo = survey.CompanyNo;
                context.Company.Add(survey.Company);
                context.SaveChanges();
                survey.CompanyID = survey.Company.CompanyID;
            }
            context.SurveyModel.Add(survey);
            //遍历所有的职位,生成标签
            List <SkillTag>  allTags   = context.SkillTag.ToList();
            List <SkillTags> matchTags = new List <SkillTags>();

            try
            {
                foreach (Position position in survey.Position)
                {
                    foreach (SkillTag tag in allTags)
                    {
                        if (!string.IsNullOrEmpty(position.PositionDesc))
                        {
                            string desc     = position.PositionDesc.ToLower().Trim();
                            string tagLower = tag.TagName.ToLower();
                            if (desc.Contains(tagLower))
                            {
                                SkillTags matchTag = new SkillTags();
                                matchTag.ID         = Guid.NewGuid().ToString();
                                matchTag.PositionID = position.PositionID;
                                matchTag.TagID      = tag.TagID;
                                matchTags.Add(matchTag);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            //保存的时候进行验证
            context.Configuration.ValidateOnSaveEnabled = false;
            //自动添加匹配的职位标签
            context.SkillTags.AddRange(matchTags);
            return(context.SaveChanges());
        }