예제 #1
0
        //#region  internal function....

        //private string cacheKey(string id)
        //{
        //    return String.Concat(this.toolbox.Options.Value.CourseCachePrefix, id);
        //}



        //private async Task<Course> loaderAsync(string id)
        //{


        //    var obj = await this.toolbox.Cachor.Get<Course>(cacheKey(id), async () =>
        //    {

        //        var entity = await this.toolbox.Reader.GetRepositoryAsync<CourseEntity>()
        //                .SingleAsync(C => C.ID == id);

        //        var rev = this.toolbox.Mapper.Map<Course>(entity);

        //        if (rev == null)
        //        {
        //            return null;
        //        }

        //        rev.Region = new UserPropVal
        //        {
        //            Code = entity.RegionCode,
        //            Name = entity.RegionName

        //        };
        //        rev.School = new UserPropVal
        //        {
        //            Name = entity.SchoolName,
        //            Code = entity.SchoolCode

        //        };
        //        rev.Creator = new UserPropVal
        //        {
        //            Code = entity.CreatorCode,
        //            Name = entity.CreatorName
        //        };

        //        //标签
        //        var tag = await this.toolbox.Reader.GetRepositoryAsync<TagsEntity>()
        //                    .Query(t => t.CourseId == id);

        //        rev.Tag = this.TagFromEntity(tag);



        //        //引用的学程
        //        var ds = await this.toolbox.Reader.GetRepositoryAsync<QuoteDsEntity>()
        //                .Query(q => q.CourseId == id);

        //        rev.DsItems = this.DsFromEntity(ds);


        //        ////引用人
        //        //var collabrators = await this.toolbox.Reader.GetRepositoryAsync<CollabratorEntity>()
        //        //                .Query(c => c.CourseId == id);

        //        //if (collabrators.NoData() is false)
        //        //{
        //        //    rev.Collaborator = new Lazy<CollabratorVal>(() =>
        //        //    { //rev.Collaborator.Binder();

        //        //        var rev = new CollabratorVal();
        //        //        foreach (var item in collabrators)
        //        //        {
        //        //            rev.Add(new(item.ObjId));
        //        //        }
        //        //        return rev;
        //        //    });
        //        //}

        //        return rev;

        //    });


        //    if (obj is null)
        //    {
        //        return null;
        //    }



        //    this._vf.Register(obj, obj => obj.CollaboratorLib, async () => {

        //        //引用人
        //        var collabrators = await this.toolbox.Reader.GetRepositoryAsync<CollabratorEntity>()
        //                        .Query(c => c.CourseId == id);

        //        if (collabrators.NoData() is false)
        //        {

        //                var rev = new CollabratorVal();
        //                foreach (var item in collabrators)
        //                {
        //                  rev.Add(new(item.ObjId));
        //                }
        //                return rev;
        //        }

        //        return null;
        //    });



        //    return obj;
        //}


        //private IList<QuoteDSVal> DsFromEntity(IList<QuoteDsEntity> entities)
        //{
        //    if (entities == null || entities.Count == 0)
        //    {
        //        return null;
        //    }

        //    var rev = new List<QuoteDSVal>();

        //    foreach (var item in entities)
        //    {
        //        rev.Add(new QuoteDSVal
        //        {
        //            IsOpen = item.IsOpen,
        //            CatalogId = item.CatalogId,
        //            DsId = item.DsId,
        //            DsName = item.DsName,
        //            OperatorId = item.OperatorId,
        //            OperatorName = item.OperatorName,
        //            SortVal = item.SortVal,
        //            IsOriginal = item.IsOriginal,
        //            IsShared = item.IsShared
        //        });
        //    }
        //    return rev;
        //}

        //private TagVal TagFromEntity(IList<TagsEntity> entity)
        //{

        //    if (entity == null || entity.Count == 0)
        //    {
        //        return null;
        //    }

        //    var tagVal = new TagVal
        //    {
        //        Items = new List<TagItem>()
        //    };


        //    foreach (var item in entity)
        //    {

        //        if (String.IsNullOrEmpty(item.TypeName))
        //        {
        //            tagVal.Name = item.Name;
        //            tagVal.Id = item.AssetId;
        //            continue;
        //        }
        //        tagVal.Items.Add(new TagItem
        //        {
        //            Name = item.Name,
        //            TypeName = item.TypeName
        //        });

        //    }

        //    return tagVal;
        //}

        //private async Task<bool> save(Course course)
        //{
        //    bool rev = await this.toolbox.Cachor.SetAsync(this.cacheKey(course.ID), course);
        //    if (rev)
        //    {
        //        await this.toolbox.Sender.SendAsync(course.Events);
        //    }

        //    return rev;

        //}

        //#endregion

        public async Task <string> CreateAsync(CreateCourseCommand cmd, UserPropVal region, UserPropVal school, UserPropVal creator)
        {
            var course = this.toolbox.Mapper.Map <Course>(cmd.dTO);

            course.ID = cmd.CommandId;

            course.Apply(this.toolbox.DomainSetter[DomainSetter.Mapper]);

            course.Create(region, school, creator);

            await this._loader.Save(course);


            return(course.ID);
        }
예제 #2
0
        public async Task <ReturnVal <string> > Create(CreateCourseDTO dTO)
        {
            var region = await this._user.Get(AppUserFlagData.OrgRegion);

            var school = await this._user.Get(AppUserFlagData.OrgSchool);

            var creator = new UserPropVal
            {
                Code = this._user.UserId,
                Name = this._user.UserName
            };

            string rev;

            if (String.IsNullOrEmpty(dTO.Id))
            {
                var id = _idTool.ID();

                var sc = await this._user.GetSchool();

                var userRev = await this._puserSvc.CreateCourse(new PltUserParam(this._user.UserId, this._user.UserName, sc.Code, (await this._user.GetRegion()).Code, sc.Name), id);

                if (userRev is false)
                {
                    return(this.RetErr <string>("用户信息异常"));
                }

                rev = await this._courseSvc.CreateAsync(new CreateCourseCommand(dTO) { CommandId = id }, region, school, creator);
            }
            else
            {
                rev = await this._courseSvc.UpdateAsunc(dTO, this._user.UserId);
            }


            return(this.RetOk(rev));
        }