示例#1
0
        public static Models.Resturant DataToModel(DataLayer.Resturant data)
        {
            Models.Resturant r = new Models.Resturant();
            r.rs_id    = data.rs_id;
            r.Name     = data.Name;
            r.Address  = data.Address;
            r.City     = data.City;
            r.State    = data.State;
            r.FoodType = data.FoodType;
            r.Reviews  = new List <Models.Review>();

            foreach (var rev in data.Reviews)
            {
                var tmp = new Models.Review
                {
                    rv_id   = rev.rv_id,
                    Author  = rev.Author,
                    Rating  = rev.Rating,
                    Comment = rev.Comment
                };
                r.Reviews.Add(tmp);
            }

            return(r);
        }
 public void addResturant(Models.Resturant model)
 {
     using (var dbcontext = new ResturantDBEntities())
     {
         dbcontext.Resturants.Add(ModelToData(model));
         dbcontext.SaveChanges();
     }
 }
示例#3
0
 public void TestMapping()
 {
     Models.Resturant    r    = new Models.Resturant();
     DataLayer.Resturant r1   = new DataLayer.Resturant();
     Models.Resturant    tmp  = DataLayer.DataManager.DataToModel(r1);
     DataLayer.Resturant tmp1 = DataLayer.DataManager.ModelToData(r);
     Assert.AreEqual(r.GetType(), tmp.GetType());
     Assert.AreEqual(r1.GetType(), tmp1.GetType());
 }
 static void showAllReviewForResturant()
 {
     resturant = GetResturant();
     Console.WriteLine("Show all reviews for:{0}  at  {1}", resturant.Name, resturant.Address);
     foreach (var rev in resturant.Reviews)
     {
         Console.WriteLine(rev.Author);
         Console.WriteLine(rev.Rating);
         Console.WriteLine(rev.Comment + "\n\r\n\r\n\r");
     }
 }
示例#5
0
 public ActionResult Update(Models.Resturant resturant)
 {
     try
     {
         bl.updateResturant(resturant);
         Response.Redirect("~/Home/GetAll");
     }
     catch (Exception ex)
     {
         logger.LogException(NLog.LogLevel.Error, "Controller: Function: Update: " + ex.Message, ex);
         return(View());
     }
     return(View());
 }
示例#6
0
 public ActionResult Add(Models.Resturant resturant)
 {
     try
     {
         bl.addResturant(resturant);
         //RedirectToAction("GetAll", "Home"); <-- doesn't work!
         Response.Redirect("~/Home/GetAll");
     }
     catch (Exception ex)
     {
         //NLog goes here
         logger.LogException(NLog.LogLevel.Error, "Controller: Function: Update: " + ex.Message, ex);
         return(View());
     }
     return(View());
 }
示例#7
0
        public void TestAddResturant()
        {
            DataLayer.DataManager dm   = new DataLayer.DataManager();
            Models.Resturant      test = new Models.Resturant();
            test.Name     = "Mortons Steak House";
            test.Address  = "4390 Suncoast Dr.";
            test.City     = "Costa Mesa";
            test.State    = "CA";
            test.FoodType = "American";
            dm.addResturant(test);
            List <Models.Resturant> list = dm.GetResturants().ToList();

            Models.Resturant verify = list.Where(x => x.Name == "Mortons Steak House").FirstOrDefault();

            Assert.AreEqual(test.Name, verify.Name);
        }
        //Mapping

        public static Resturant ModelToData(Models.Resturant model)
        {
            DataLayer.Resturant r = new DataLayer.Resturant();
            r.Name     = model.Name;
            r.Address  = model.Address;
            r.City     = model.City;
            r.State    = model.State;
            r.FoodType = model.FoodType;
            foreach (var rev in model.Reviews)
            {
                var tmp = new DataLayer.Review
                {
                    Author  = rev.Author,
                    Rating  = rev.Rating,
                    Comment = rev.Comment
                };
                r.Reviews.Add(tmp);
            }

            return(r);
        }
 static void showResturantDetails()
 {
     resturant = GetResturant();
     Console.WriteLine("{0}  {1} {2}, {3}. {4}", resturant.Name, resturant.Address, resturant.City, resturant.State, resturant.FoodType);
 }
示例#10
0
 public void updateResturant(Models.Resturant modelRes)
 {
     DataLayer.Resturant dataRes = ModelToData(modelRes);
     data.Update(dataRes);
 }
示例#11
0
 public void addResturant(Models.Resturant modelRes)
 {
     DataLayer.Resturant dataRes = ModelToData(modelRes);
     data.Add(dataRes);
 }
示例#12
0
 public void deleteResturant(Models.Resturant modelRes)
 {
     DataLayer.Resturant dataRes = ModelToData(modelRes);
     data.deleteResturant(dataRes);
 }