Example #1
0
        public async Task <_ <TagEntity> > UpdateTag(TagEntity data)
        {
            data.Should().NotBeNull("update tag data");
            data.Id.Should().NotBeNullOrEmpty("update tag uid");
            data.TagName.Should().NotBeNullOrEmpty("update tag tag name");

            var model = await this._tagRepo.QueryOneAsync(x => x.Id == data.Id);

            model.Should().NotBeNull();

            model.SetField(new
            {
                data.TagName,
                data.Desc,
                data.Icon,
                data.Image
            });

            var res = new _ <TagEntity>();

            if (await this._tagRepo.ExistAsync(x => x.Id != model.Id && x.TagName == model.TagName))
            {
                return(res.SetErrorMsg("存在同名标签"));
            }

            await this._tagRepo.UpdateAsync(model);

            return(res.SetSuccessData(model));
        }
Example #2
0
        public async Task <_ <TagEntity> > AddTag(TagEntity data)
        {
            data.Should().NotBeNull("add tag data");
            data.TagName.Should().NotBeNullOrEmpty("add tag tag name");

            var res = new _ <TagEntity>();

            if (await this._tagRepo.ExistAsync(x => x.TagName == data.TagName))
            {
                return(res.SetErrorMsg("存在同名标签"));
            }

            data.InitEntity();

            await this._tagRepo.InsertAsync(data);

            return(res.SetSuccessData(data));
        }