Beispiel #1
0
        //Create List to store your CSV data
        public List<Models.Holidayhome> parseHolidayhomes()
        {
            CsvReader csv = new CsvReader(reader, true);
            int fieldCount = csv.FieldCount;
            List<Holidayhome> holidaylist = new List<Holidayhome>();

            String[] headers = csv.GetFieldHeaders();

            while (csv.ReadNextRecord())
            {
                Holidayhome exObj = new Holidayhome();

                for (int i = 0; i < fieldCount; i++)
                {
                    if (headers[i].Equals("holidayhomeno"))  {exObj.holidayhomeno = csv[i];}
                    else if (headers[i].Equals("address1")) { exObj.address1 = csv[i]; }
                    else if (headers[i].Equals("address2")) { exObj.address2 = csv[i]; }
                    else if (headers[i].Equals("country"))  { exObj.country = csv[i];  }
                    else if (headers[i].Equals("email"))    { exObj.email = csv[i];    }
                    else if (headers[i].Equals("contactno")){ exObj.contactno = csv[i];}
                    else if (headers[i].Equals("amenities")){ exObj.amenities = csv[i];}
                    else if (headers[i].Equals("price")) { exObj.price = csv[i]; }

                }

                holidaylist.Add(exObj);
            }

               return holidaylist;
        }
Beispiel #2
0
        public bool updateHolidayhomeDb(Holidayhome hse)
        {
            db.Entry(hse).State = EntityState.Modified;

                db.SaveChanges();
                return true;
        }
Beispiel #3
0
        //Create List to store your CSV data
        List<Models.Holidayhome> IDataParser.parseHolidayhomes()
        {
            CsvReader csv = new CsvReader(reader, true);
            int fieldCount = csv.FieldCount;
            List<Holidayhome> holidayhomes = new List<Holidayhome>();

            String[] headers = csv.GetFieldHeaders();

               Holidayhome exObj = new Holidayhome();

            while (csv.ReadNextRecord())
            {

                for (int i = 0; i < fieldCount; i++)
                {
                    if (headers[i].Equals("location"))  {exObj.location = csv[i];}
                    else if (headers[i].Equals("address1")) { exObj.address1 = csv[i]; }
                    else if (headers[i].Equals("address2")) { exObj.address2 = csv[i]; }
                    else if (headers[i].Equals("country"))  { exObj.country = csv[i];  }
                    else if (headers[i].Equals("email"))    { exObj.email = csv[i];    }
                    else if (headers[i].Equals("contactno")){ exObj.contactno = csv[i];}
                    else if (headers[i].Equals("amenities")){ exObj.amenities = csv[i];}
                }

                holidayhomes.Add(exObj);
            }

               return holidayhomes;
        }
Beispiel #4
0
 public ActionResult Edit(Holidayhome holidayhome)
 {
     if (ModelState.IsValid)
     {
         db.Entry(holidayhome).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(holidayhome);
 }
Beispiel #5
0
        public ActionResult Create(Holidayhome holidayhome)
        {
            if (ModelState.IsValid)
            {
                db.Holidayhomes.Add(holidayhome);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(holidayhome);
        }
Beispiel #6
0
        public bool addHolidayhomeDb(Holidayhome hse)
        {
            Holidayhome home = new Holidayhome();

                home = db.Holidayhomes.Add(hse);

            if (home is Holidayhome)
            {
                db.SaveChanges();
                return true;
            }
            return false;
        }
Beispiel #7
0
 public bool updateHolidayhomeDb(Holidayhome hse)
 {
     db.Entry(hse).State = EntityState.Modified;
     try
     {
         db.SaveChanges();
         return true;
     }
     catch (Exception exp)
     {
         // do something
         return false;
     }
 }
Beispiel #8
0
 public ActionResult Create(Holidayhome Holidayhome)
 {
     try
     {
         if (ModelState.IsValid)
         {
             HolidayhomeRepository.InsertHolidayhome(Holidayhome);
             HolidayhomeRepository.Save();
             return RedirectToAction("Index");
         }
     }
     catch (DataException)
     {
         //Log the error (add a variable name after DataException)
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     return View(Holidayhome);
 }
Beispiel #9
0
        public bool addHolidayhomeDb(Holidayhome hse)
        {
            Holidayhome home = new Holidayhome();
            try
            {
                home = db.Holidayhomes.Add(hse);
            }

            catch (Exception exp)
            {
                Exception j = exp;
                return false;
                //do something
            }

            if (home is Holidayhome)
            {
                db.SaveChanges();
                return true;
            }
            return false;
        }
Beispiel #10
0
        public void parseHolidayhomesTest1()
        {
            StreamReader reader = new StreamReader("d:\\nci\\holidayhomes.csv");
                  CSVParser target = new CSVParser();
                  target.setStreamSource(reader);

                  Holidayhome hse = new Holidayhome();
                  hse.holidayhomeno="Spain";
                  hse.address1="San Costa";
                  hse.address2="Valencia";
                  hse.country = "Spain";
                  hse.email="*****@*****.**";
                  hse.contactno="+353 18767352";
                  hse.amenities="Swimming Pool| Gym | Sauna";
                  hse.price="445";

                 List<Holidayhome> expected = new List<Holidayhome>();
                 expected.Add(hse);
                 List<Holidayhome> actual = target.parseHolidayhomes();

                 Assert.AreEqual(expected[0].address1, actual[0].address1);
                 Assert.AreEqual(expected[0].country, actual[0].country);
                 Assert.AreEqual(expected[0].contactno, actual[0].contactno);
        }
Beispiel #11
0
 public void UpdateHolidayhome(Holidayhome Holidayhome)
 {
     context.Entry(Holidayhome).State = EntityState.Modified;
 }
Beispiel #12
0
 public void InsertHolidayhome(Holidayhome Holidayhome)
 {
     context.Holidayhomes.Add(Holidayhome);
 }