Example #1
0
        public async Task <InitWorkFlowOutput> Create(CreateUserCourseExperienceInput input)
        {
            var submituser = (await(from c in _trainUserExperienceRepository.GetAll()
                                    .Where(x => !x.IsDeleted && x.TrainId == input.CourseId && x.Type == TrainExperienceType.Course)
                                    select "u_" + c.UserId).ToListAsync());
            var createuser = await base.GetCurrentUserAsync();

            submituser.Add("u_" + createuser.Id);
            var newmodel = new UserCourseExperience()
            {
                UserId        = input.UserId,
                CourseId      = input.CourseId,
                ExperienceId  = "",
                SubmitUsers   = string.Join(",", submituser.Distinct()),
                DealWithUsers = input.DealWithUsers,
                Status        = input.Status,
                CopyForUsers  = input.CopyForUsers
            };

            newmodel.Status = 0;
            await _repository.InsertAsync(newmodel);

            return(new InitWorkFlowOutput()
            {
                InStanceId = newmodel.Id.ToString()
            });
        }
Example #2
0
        private UserCourseExperienceLogDto GetChangeModel(UserCourseExperience model)
        {
            var ret = model.MapTo <UserCourseExperienceLogDto>();

            return(ret);
        }
Example #3
0
        /// <summary>
        /// 修改一个UserCourseExperience
        /// </summary>
        /// <param name="input">实体</param>
        /// <returns></returns>
        public async Task Update(UpdateUserCourseExperienceInput input)
        {
            if (input.InStanceId != Guid.Empty)
            {
                var dbmodel = await _repository.FirstOrDefaultAsync(x => x.Id == input.InStanceId);

                if (dbmodel == null)
                {
                    throw new UserFriendlyException((int)ErrorCode.CodeValErr, "该数据不存在!");
                }
                var logModel = new UserCourseExperience();
                if (input.IsUpdateForChange)
                {
                    logModel = dbmodel.DeepClone <UserCourseExperience>();
                }
                var dbexp = string.IsNullOrEmpty(dbmodel.ExperienceId)
                    ? new List <string>()
                    : dbmodel.ExperienceId.Split(',').ToList();
                if (string.IsNullOrEmpty(input.ExperienceId))
                {
                    throw new UserFriendlyException((int)ErrorCode.CodeValErr, "请至少选择一条心得体会汇总!");
                }
                var inputexp = input.ExperienceId.Split(',').ToList();
                var newexp   = inputexp.Except(dbexp).ToList();
                dbexp.AddRange(newexp);
                dbmodel.ExperienceId = string.Join(",", dbexp);
                await _repository.UpdateAsync(dbmodel);

                if (input.IsUpdateForChange)
                {
                    var flowModel = _workFlowCacheManager.GetWorkFlowModelFromCache(input.FlowId);
                    if (flowModel == null)
                    {
                        throw new UserFriendlyException((int)ErrorCode.CodeValErr, "流程不存在");
                    }
                    var logs = GetChangeModel(logModel).GetColumnAllLogs(GetChangeModel(dbmodel));
                    await _projectAuditManager.InsertAsync(logs, input.InStanceId.ToString(),
                                                           flowModel.TitleField.Table);
                }
                //采纳心得体会加积分
                var course = _courseRepository.Get(dbmodel.CourseId);
                var set    = await _courseSettingAppService.GetSetVal(course.LearnType, course.IsSpecial);

                newexp.ForEach(async x =>
                {
                    var exp   = _experienceRepository.Get(Guid.Parse(x));
                    exp.IsUse = true;
                    _experienceRepository.Update(exp);
                    if (set.ExperienceScore > 0)
                    {
                        await _trainScoreRecordAppService.Create(new CreateUserTrainScoreRecordInput()
                        {
                            FromId   = dbmodel.CourseId,
                            FromType = TrainScoreFromType.CourseExperience,
                            Score    = set.ExperienceScore,
                            UserId   = exp.CreatorUserId ?? 0
                        });
                    }
                });
            }
            else
            {
                throw new UserFriendlyException((int)ErrorCode.CodeValErr, "该数据不存在!");
            }
        }