public ActionResult Create(Salesman Salesman)
 {
     if (ModelState.IsValid)
     {
         try
         {
             
             // TODO: Add insert logic here
             this.UpdateModel(Salesman);
             svc.Save(Salesman);
             return RedirectToAction("Index");
             
         }
         catch
         {
             return View(Salesman);
         }
     }
     return View(Salesman);
 }
示例#2
0
        public int ImportSalesman(Stream csvFile)
        {
            StreamReader textReader = new StreamReader(csvFile);
            CsvReader CSV = new CsvReader(textReader);
            CSV.Configuration.IsHeaderCaseSensitive = false;
            CSV.Configuration.TrimFields = true;
            CSV.Configuration.WillThrowOnMissingField = false;

            int count = 0;

            while (CSV.Read())
            {
                string name = CSV.GetField<string>("name");

                if (salesmanSvc.GetByName(name)!=null)
                {
                    //update record?
                }
                else
                {
                    Salesman salesman = new Salesman
                    {
                        Name = name
                    };
                    try
                    {
                        salesmanSvc.Save(salesman);

                    }
                    catch (Exception e)
                    {
                        //throw new Exception("Save Customer Error", e);
                    }
                }
            }
            
            return count;
        }