public async Task <int> Save(List <ProductResource> products) { int id = 0; try { json = JsonConvert.SerializeObject(products.ToArray(), Formatting.Indented); filename = Path.Combine(_hostingEnvironment.ContentRootPath, _appSettings.Value.JsonSavePath, RandomString.GenerateRandomString(10) + ".json"); //write string to file System.IO.File.WriteAllText(filename, json); ProductPath path = new ProductPath { JsonFilePath = filename }; await _productPathRepository.AddAsync(path); await _unitOfWork.CompleteAsync(); id = path.Id; } catch (Exception ex) { _logService.LogException(ex, "Save File Path"); } return(id); }
public void Add() { if (this.pathName == null || this.pathName.Trim().Equals(string.Empty) || this.pathDir == null || this.pathDir.Trim().Equals(string.Empty)) { this.Hint = "目录名、目录路径不能为空!"; } else { ProductPath item = new ProductPath(); item.Name = this.pathName.Trim(); item.Path = this.pathDir.Trim(); this.DirList.Add(item); config.ListProductPath = this.DirList.ToList(); config.WriteConfigToFile(); this.Hint = "常用产品目录保存成功!"; this.PathName = ""; this.PathDir = ""; } }
public void Remove(ProductPath product) { _context.ProductPaths.Remove(product); }
public void Update(ProductPath product) { _context.ProductPaths.Update(product); }
public async Task AddAsync(ProductPath product) { await _context.ProductPaths.AddAsync(product); }