public IList<OrderWievModel> ParseFile(string path) { List<string> stringFile = new List<string>(); List<OrderWievModel> result = new List<OrderWievModel>(); using ( StreamReader file = new StreamReader(path)) { string tempString = file.ReadLine(); while (tempString != null) { stringFile.Add(tempString); tempString = file.ReadLine(); } } char separator = Convert.ToChar(ConfigurationManager.AppSettings["Separator"]); foreach (var item in stringFile) { string[] partsString = item.Split(separator); int datePart = 0; //входящая строка вида дата,клиент,товар,сумма разбивается на 4 части int clientPart = 1; int productPart = 2; int costPart = 3; OrderWievModel orderWM = new OrderWievModel() { DateOrder = ConvertToDate(partsString[datePart]), NameClient = partsString[clientPart], Product = partsString[productPart], CostProduct = Convert.ToDouble(partsString[costPart]) }; result.Add(orderWM); } return result; }
public void AddOrder(OrderWievModel orderWM) { using (BaseContext ctx = new BaseContext()) { ClientHelper clientHelper = new ClientHelper(); Order order = new Order() { DateOrder = orderWM.DateOrder, IdClient = clientHelper.GetIdClient(orderWM.NameClient), Product = orderWM.Product, Cost = orderWM.CostProduct }; ctx.Orders.Add(order); ctx.SaveChanges(); } }