Beispiel #1
0
        /// <summary>
        /// 更新一个对象,value=null或者id找不到则返回null,内部已经做了访问权限判断
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public async Task <T> UpdateAsync(string accid, T value)
        {
            bool bOk = await CanUpdateAsync(accid, value.Id);

            if (bOk == false)
            {
                return(null);
            }

            var entity = value as ListableEntity;

            if (entity != null)
            {
                await UpdateProtectListableEntityAsync(accid, entity);
            }

            var res = await GetDataSet(accid).FirstOrDefaultAsync(d => d.Id == value.Id);

            if (res == null)
            {
                return(null);
            }
            DataCopyer.CopyDataTo(value, res);
            await context.SaveChangesAsync();

            return(res);
        }
Beispiel #2
0
        /// <summary>
        /// 更新一个对象,value=null或者id找不到则返回null,内部已经做了访问权限判断
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public T Update(string accid, T value)
        {
            if (CanUpdate(accid, value.Id) == false)
            {
                return(null);
            }

            ListableEntity entity = value as ListableEntity;

            if (entity != null)
            {
                UpdateProtectListableEntity(accid, entity);
            }

            var res = GetDataSet(accid).FirstOrDefault(d => d.Id == value.Id);

            if (res == null)
            {
                return(null);
            }
            DataCopyer.CopyDataTo(value, res);
            context.SaveChangesAsync();
            return(res);
        }