Exemple #1
0
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > Modify(SysOrganizeParam model)
        {
            var result = new ApiResult <string>();

            try
            {
                var organizeModel = model.MapTo <SysOrganizeParam, SysOrganize>();
                organizeModel.ParentId     = model.Parent[model.Parent.Count - 1];
                organizeModel.ParentIdList = string.Join(",", model.Parent) + "," + organizeModel.Id;
                //根据父级查询等级
                var parentModel = await _thisRepository.GetModelAsync(m => m.Id == organizeModel.ParentId);

                if (parentModel != null)
                {
                    organizeModel.Layer = parentModel.Layer + 1;
                }
                await _thisRepository.UpdateAsync(organizeModel, m => new { m.CreateUser, m.CreateTime, m.IsDel });
            }
            catch (Exception ex)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                result.Message    = ex.Message;
            }
            return(result);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > Add(SysOrganizeParam model)
        {
            var result = new ApiResult <string>();

            try
            {
                var organizeModel = model.MapTo <SysOrganizeParam, SysOrganize>();
                organizeModel.Id           = Unique.Id();
                organizeModel.ParentId     = model.Parent.GetLong()[model.Parent.GetLong().Count - 1];
                organizeModel.ParentIdList = string.Join(",", model.Parent.ToArray()) + "," + organizeModel.Id;
                organizeModel.CreateUser   = "******";
                //根据父级查询等级
                var parentModel = await _thisRepository.GetModelAsync(m => m.Id == organizeModel.ParentId);

                if (parentModel != null)
                {
                    organizeModel.Layer = parentModel.Layer + 1;
                }
                await _thisRepository.AddAsync(organizeModel);
            }
            catch (Exception ex)
            {
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                result.Message    = ex.Message;
            }
            return(result);
        }
 public async Task <ApiResult <string> > Modify([FromBody] SysOrganizeParam model) => await _sysOrganizeService.Modify(model);