public void SetUp() { componentService = ComponentService.Create(); componentService .UseAutofac() .UseCommonComponent(); }
public TransactionResult <Component> AddComponent(Component info) { TransactionResult <Component> result = new TransactionResult <Component>(); var serviceResult = componentService.Create(info); if (serviceResult.ActionResult & serviceResult.HavingData) { result.Data = serviceResult.Data; } else { result.Code = 103; result.Message = "暂无数据"; } return(result); }
public void Execute() { var uow = new UnitOfWork(); var service = new ComponentService(null, uow); var text = System.IO.File.ReadAllText(_filename, Encoding.Default); var lines = text.Split(new[] { "\r\n" }, StringSplitOptions.None); try { foreach (var line in lines) { var columns = line.Split(';'); if (columns.Length == 8) { var category = CleanString(columns[0]); var typeNo = CleanString(columns[2]); var typeSe = CleanString(columns[3]); var vendor = CleanString(columns[4]); var article = CleanString(columns[5]); var descNo = CleanString(columns[6]); var descSe = CleanString(columns[7]); if (article.Length > 0 && (category.Length > 1 || typeNo.Length > 1)) { var components = service.GetAll(); var compNo = components.FirstOrDefault(c => c.Name == article && c.Description == descNo && c.LanguageId == 1); var compSe = components.FirstOrDefault(c => c.Name == article && c.Description == descSe && c.LanguageId == 2); if (compNo == null) { compNo = new Component { Name = article, Description = descNo, Vendor = FindOrCreateVendor(vendor, uow), LanguageId = 1, Category = FindOrCreateCategory(category, 1, uow), Type = FindOrCreateType(typeNo, 1, uow) }; service.Create(compNo); uow.Commit(); } if (compSe == null) { compSe = new Component { Name = article, Description = descSe, Vendor = compNo.Vendor, LanguageId = 2, Category = CreateLangCategory(compNo.Category, 2, uow), Type = CreateLangType(typeSe, compNo.Type, 2, uow), TranslatedFrom = compNo }; service.Create(compSe); uow.Commit(); } } } } } catch (DbEntityValidationException e) { Console.WriteLine(e.Message); } }