Пример #1
0
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="dto"></param>
        protected virtual async Task <TDataModelType> AddAsync(TDataModelType data)
        {
            Ensure.NotNull(data, nameof(data));

            data.CreateDate     = DateTime.Now;
            data.LastModifyDate = DateTime.Now;
            TDataModelType result = (await CSLDbContext.Set <TDataModelType>().AddAsync(data)).Entity;
            await CSLDbContext.SaveChangesAsync();

            return(result);
        }
Пример #2
0
        /// <summary>
        /// 根据 ID 删除实数据
        /// </summary>
        /// <param name="id"></param>
        public async Task DeleteByIdAsync(int id)
        {
            TDataModelType data = CSLDbContext.Set <TDataModelType>().Find(id);

            if (data == null)
            {
                throw new ArgumentException($"指定删除的数据(id:{id})不存在");
            }

            CSLDbContext.Set <TDataModelType>().Remove(data);
            await CSLDbContext.SaveChangesAsync();
        }
Пример #3
0
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="dto"></param>
        public virtual async Task <TDataModelType> AddAsync(TDataModelType data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            data.CreateDate     = DateTime.Now;
            data.LastModifyDate = DateTime.Now;
            TDataModelType result = (await CSLDbContext.Set <TDataModelType>().AddAsync(data)).Entity;
            await CSLDbContext.SaveChangesAsync();

            return(result);
        }
Пример #4
0
        /// <summary>
        /// 编辑数据
        /// </summary>
        /// <param name="dto"></param>
        public virtual async Task UpdateAsync(TDataModelType data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            data.LastModifyDate = DateTime.Now;

            TDataModelType entity    = CSLDbContext.Set <TDataModelType>().Where(e => e.Id == data.Id).FirstOrDefault();
            Type           modelType = typeof(TDataModelType);

            foreach (string propName in typeof(TDataModelType).GetProperties().Select(p => p.Name).ToList())
            {
                modelType.GetProperty(propName).SetValue(entity, modelType.GetProperty(propName).GetValue(data));
            }
            CSLDbContext.Set <TDataModelType>().Update(entity);
            await CSLDbContext.SaveChangesAsync();
        }
Пример #5
0
        public virtual async Task <QiniuStorageInfo> UpdateFileStorageInfo(QiniuStorageInfo qiniuStorageInfo)
        {
            Ensure.NotNull(qiniuStorageInfo, nameof(qiniuStorageInfo));

            QiniuStorageInfo entityToUpdate = CSLDbContext.QiniuStorageInfoes.Where(item => item.FullName == qiniuStorageInfo.FullName).FirstOrDefault();

            if (entityToUpdate != null)
            {
                CSLDbContext.QiniuStorageInfoes.Remove(entityToUpdate);
            }

            qiniuStorageInfo.CreateDate     = DateTime.Now;
            qiniuStorageInfo.LastModifyDate = DateTime.Now;
            EntityEntry <QiniuStorageInfo> entry = await CSLDbContext.QiniuStorageInfoes.AddAsync(qiniuStorageInfo);

            await CSLDbContext.SaveChangesAsync();

            return(entry.Entity);
        }