private void ProcessingTask(object filePath) { CsvParser csvParser = new CsvParser((string)filePath, Delimiter); DAL.IRepository <DAL.Models.Client> clientRepository = new DAL.ClientRepository(); DAL.IRepository <DAL.Models.Manager> managerRepository = new DAL.ManagerRepository(); DAL.IRepository <DAL.Models.Goods> goodsRepository = new DAL.GoodsRepository(); DAL.IRepository <DAL.Models.Sales> salesRepository = new DAL.SalesRepository(); var managerSecondName = Path.GetFileName((string)filePath).Split(new char[] { '_' })[0]; var manager = managerRepository.Items.FirstOrDefault(x => x.SecondName.ToLower() == managerSecondName.Trim().ToLower()); if (manager == null) { return; } var rows = csvParser.GetRecords().Select(r => new ImportedDataRow() { Date = DateTime.Parse(r[0]), Client = r[1], Goods = r[2], Total = double.Parse(r[3]) }); foreach (var r in rows) { lock (syncObj) { var c = clientRepository.Items.FirstOrDefault(x => x.Name.ToLower() == r.Client.Trim().ToLower()); var g = goodsRepository.Items.FirstOrDefault(x => x.Name.ToLower() == r.Goods.Trim().ToLower()); if (c == null) { clientRepository.Add(new DAL.Models.Client() { Name = r.Client }); clientRepository.SaveChanges(); } if (g == null) { goodsRepository.Add(new DAL.Models.Goods() { Name = r.Goods }); goodsRepository.SaveChanges(); } salesRepository.Add(new DAL.Models.Sales() { Date = r.Date, Manager = manager, Client = clientRepository.Items.FirstOrDefault(x => x.Name == r.Client), Goodds = goodsRepository.Items.FirstOrDefault(x => x.Name == r.Goods), Cost = r.Total }); salesRepository.SaveChanges(); } } }
public async void Test1() { var clientRepository = new DAL.ClientRepository(_logger, true); var newCient = new Client() { ClientName = "Lorikeet Family", ClientDescription = "This family is living a remote place in Sistan and Balouchestan province of Iran.", GoogleMapAddress = "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d4391842.965895599!2d58.789367776186324!3d28.22707811997935!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x3ee7373a9afe43d5%3A0xe92f486ae9df1408!2sSistan+and+Baluchestan+Province%2C+Iran!5e1!3m2!1sen!2sus!4v1560554452394!5m2!1sen!2sus", }; await clientRepository.AddAsync(newCient); var repository = new DAL.ProjectRepository(_logger, true); var newProject = new Project() { Name = "Buiding Bathroom", MoneyRaised = 1700, ClientId = newCient.Id, Pictures = new List <Picture> { new Picture() { Type = PictureType.Image, Url = "images/project1/location00.jpeg" }, new Picture() { Type = PictureType.Image, Url = "images/project1/location01.jpeg" }, new Picture() { Type = PictureType.Image, Url = "images/project1/location02.jpeg" }, new Picture() { Type = PictureType.Image, Url = "images/project1/location03.jpeg" }, new Picture() { Type = PictureType.Image, Url = "images/project1/location04.jpeg" }, new Picture() { Type = PictureType.Image, Url = "images/project1/location05.jpeg" }, new Picture() { Type = PictureType.Image, Url = "images/project1/location06.jpeg" }, new Picture() { Type = PictureType.Image, Url = "images/project1/location07.jpeg" }, } }; await repository.AddAsync(newProject); var projects = repository.GetAll().Count(); }
private void ProcessingTask() { FileStream stream = new FileStream(FilePath, FileMode.Open); CsvParser csvParser = new CsvParser(FilePath, Delimiter); DAL.IRepository <DAL.Models.Client> clientRepository = new DAL.ClientRepository(); DAL.IRepository <DAL.Models.Manager> managerRepository = new DAL.ManagerRepository(); DAL.IRepository <DAL.Models.Goods> goodsRepository = new DAL.GoodsRepository(); DAL.IRepository <DAL.Models.Sales> salesRepository = new DAL.SalesRepository(); var rows = csvParser.GetRecords().Select(r => new ImportedDataRow() { Date = DateTime.Parse(r[0]), Client = r[1], Goods = r[2], Total = double.Parse(r[3]) }); }