/// <summary> /// 新增 /// </summary> /// <param name="editRequest"></param> /// <returns></returns> public async Task <ResponseMessage <bool> > ProductAddAsync(ProductEditRequest editRequest, CancellationToken cancellationToken) { var response = new ResponseMessage <bool>() { Extension = false }; if (editRequest == null) { throw new ArgumentNullException(); } using (var transaction = await _transaction.BeginTransaction()) { try { var product = _mapper.Map <Product>(editRequest); product.Id = Guid.NewGuid().ToString(); product.Icon = editRequest.Files.Where(item => item.IsIcon).SingleOrDefault().Url; //新增图片 var images = new List <Files> { }; editRequest.Files.ForEach(img => { images.Add(new Files { IsDeleted = false, Id = Guid.NewGuid().ToString(), Url = img.Url, IsIcon = img.IsIcon, ProductId = product.Id }); }); await _filesStore.AddRangeEntityAsync(images); response.Extension = await _ProductStore.AddEntityAsync(product); await transaction.CommitAsync(cancellationToken); } catch (Exception e) { await transaction.RollbackAsync(cancellationToken); throw e; } } return(response); }
/// <summary> /// 批量新增 /// </summary> /// <param name="fileRequests"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <ResponseMessage <bool> > AddRanageAsync(List <FileRequest> fileRequests, CancellationToken cancellationToken) { var response = new ResponseMessage <bool>() { Extension = false }; if (fileRequests.Any()) { throw new ZCustomizeException(ResponseCodeEnum.NotAllow); } var files = _mapper.Map <List <Files> >(fileRequests); response.Extension = await _filesStore.AddRangeEntityAsync(files); return(response); }