/// <summary> /// 保存Logistics信息(新增/更新) /// </summary> /// <param name="updateForeignKey">更新时是否更新外键信息</param> /// <param name="dtos">要保存的LogisticsDto信息</param> /// <returns>业务操作集合</returns> public async Task <OperationResult> SaveLogisticss(bool updateForeignKey = false, params LogisticsDto[] dtos) { try { dtos.CheckNotNull("dtos"); var addDtos = dtos.Where(p => p.Id == 0).ToArray(); var updateDtos = dtos.Where(p => p.Id != 0).ToArray(); LogisticsRepo.UnitOfWork.TransactionEnabled = true; Action <LogisticsDto> checkAction = null; Func <LogisticsDto, Logistics, Logistics> updateFunc = null; if (addDtos.Length > 0) { LogisticsRepo.Insert(addDtos, checkAction, updateFunc); } if (updateDtos.Length > 0) { LogisticsRepo.Update(updateDtos, checkAction, updateFunc); } await LogisticsRepo.UnitOfWork.SaveChangesAsync(); return(new OperationResult(OperationResultType.Success, "保存成功")); } catch (Exception e) { return(new OperationResult(OperationResultType.Error, e.Message)); } }
/// <summary> /// 删除Logistics信息 /// </summary> /// <param name="ids">要删除的Id编号</param> /// <returns>业务操作结果</returns> public async Task <OperationResult> DeleteLogisticss(params int[] ids) { ids.CheckNotNull("ids"); await LogisticsRepo.RecycleAsync(p => ids.Contains(p.Id)); return(new OperationResult(OperationResultType.Success, "删除成功")); }
/// <summary> /// 保存FreightTemplate信息(新增/更新) /// </summary> /// <param name="updateForeignKey">更新时是否更新外键信息</param> /// <param name="dtos">要保存的FreightTemplateDto信息</param> /// <returns>业务操作集合</returns> public async Task <OperationResult> SaveFreightTemplates(bool updateForeignKey = false, params FreightTemplateDto[] dtos) { try { dtos.CheckNotNull("dtos"); var addDtos = dtos.Where(p => p.Id == 0).ToArray(); var updateDtos = dtos.Where(p => p.Id != 0).ToArray(); FreightTemplateRepo.UnitOfWork.TransactionEnabled = true; Action <FreightTemplateDto> checkAction = null; Func <FreightTemplateDto, FreightTemplate, FreightTemplate> updateFunc = (dto, entity) => { if (dto.Id == 0 || updateForeignKey) { entity.Logistics = LogisticsRepo.GetByKey(dto.LogisticsId); entity.Province = ProvinceRepo.GetByKey(dto.ProvinceId); } return(entity); }; if (addDtos.Length > 0) { FreightTemplateRepo.Insert(addDtos, checkAction, updateFunc); } if (updateDtos.Length > 0) { FreightTemplateRepo.Update(updateDtos, checkAction, updateFunc); } await FreightTemplateRepo.UnitOfWork.SaveChangesAsync(); return(new OperationResult(OperationResultType.Success, "保存成功")); } catch (Exception e) { return(new OperationResult(OperationResultType.Error, e.Message)); } }