Esempio n. 1
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);
        }
Esempio n. 2
0
        public bool updateHolidayhomeDb(Holidayhome hse)
        {
            db.Entry(hse).State = EntityState.Modified;

            db.SaveChanges();
            return(true);
        }
Esempio n. 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Holidayhome holidayhome = db.Holidayhomes.Find(id);

            db.Holidayhomes.Remove(holidayhome);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
 public ActionResult Edit(Holidayhome holidayhome)
 {
     if (ModelState.IsValid)
     {
         db.Entry(holidayhome).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(holidayhome));
 }
Esempio n. 6
0
        //
        // GET: /Holidayhome/Delete/5

        public ActionResult Delete(int id, bool?saveChangesError)
        {
            if (saveChangesError.GetValueOrDefault())
            {
                ViewBag.ErrorMessage = "Unable to save changes. Try again, and if the problem persists see your system administrator.";
            }
            Holidayhome Holidayhome = HolidayhomeRepository.GetHolidayhomeByID(id);

            return(View(Holidayhome));
        }
Esempio n. 7
0
        public ActionResult Create(Holidayhome holidayhome)
        {
            if (ModelState.IsValid)
            {
                db.Holidayhomes.Add(holidayhome);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(holidayhome));
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
 public bool updateHolidayhomeDb(Holidayhome hse)
 {
     db.Entry(hse).State = EntityState.Modified;
     try
     {
         db.SaveChanges();
         return(true);
     }
     catch (Exception exp)
     {
         // do something
         return(false);
     }
 }
Esempio n. 10
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);
        }
Esempio n. 11
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));
 }
Esempio n. 12
0
 public ActionResult DeleteConfirmed(int id)
 {
     try
     {
         Holidayhome Holidayhome = HolidayhomeRepository.GetHolidayhomeByID(id);
         HolidayhomeRepository.DeleteHolidayhome(id);
         HolidayhomeRepository.Save();
     }
     catch (DataException)
     {
         //Log the error (add a variable name after DataException)
         return(RedirectToAction("Delete",
                                 new System.Web.Routing.RouteValueDictionary {
             { "id", id },
             { "saveChangesError", true }
         }));
     }
     return(RedirectToAction("Index"));
 }
Esempio n. 13
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);
        }
Esempio n. 14
0
        public void DeleteHolidayhome(int HolidayhomeID)
        {
            Holidayhome Holidayhome = context.Holidayhomes.Find(HolidayhomeID);

            context.Holidayhomes.Remove(Holidayhome);
        }
Esempio n. 15
0
 public void UpdateHolidayhome(Holidayhome Holidayhome)
 {
     context.Entry(Holidayhome).State = EntityState.Modified;
 }
Esempio n. 16
0
 public void InsertHolidayhome(Holidayhome Holidayhome)
 {
     context.Holidayhomes.Add(Holidayhome);
 }
Esempio n. 17
0
        //
        // GET: /Holidayhome/Details/5

        public ViewResult Details(int id)
        {
            Holidayhome Holidayhome = HolidayhomeRepository.GetHolidayhomeByID(id);

            return(View(Holidayhome));
        }
Esempio n. 18
0
        //
        // GET: /Holidayhome/Delete/5

        public ActionResult Delete(int id)
        {
            Holidayhome holidayhome = db.Holidayhomes.Find(id);

            return(View(holidayhome));
        }
Esempio n. 19
0
        }        //

        public ActionResult Edit(int id)
        {
            Holidayhome Holidayhome = HolidayhomeRepository.GetHolidayhomeByID(id);

            return(View(Holidayhome));
        }
Esempio n. 20
0
        //
        // GET: /Holidayhome/Details/5

        public ViewResult Details(int id)
        {
            Holidayhome holidayhome = db.Holidayhomes.Find(id);

            return(View(holidayhome));
        }