public async Task <ActionResult> UpdateRestaurant(String id, [FromBody] RestaurantInfo restaurant)
        {
            if (restaurant == null)
            {
                return(BadRequest());
            }



            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }



            RestaurantInfo restaurant1 = await _restaurantInfoRepository.GetRestaurantById(id);

            if (restaurant1 == null)
            {
                return(NotFound());
            }
            _mapper.Map(restaurant, restaurant1);


            if (!await _restaurantInfoRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutRestaurantInfo(int id, RestaurantInfo restaurantInfo)
        {
            if (id != restaurantInfo.Id)
            {
                return(BadRequest());
            }

            _context.Entry(restaurantInfo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RestaurantInfoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public void TestDeserializeSingleRestaurantFromFile()
        {
            RestaurantInfo restaurant = null;

            //Arrange
            try
            {
                using (StreamReader file = File.OpenText(@"C:\Users\Raptor\Downloads\singleRestaurantJson.json"))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    restaurant = (RestaurantInfo)serializer.Deserialize(file, typeof(RestaurantInfo));
                }
            } catch (FileNotFoundException e)
            {
                Assert.Fail("File not found");
            } catch (Exception e)
            {
                Assert.Fail("Cannot deserialize into the object type");
            }
            //Act
            int actual   = restaurant.restaurantId;
            int expected = 1;

            //Assert
            Assert.AreEqual(actual, expected);
        }
        public async Task <ActionResult <RestaurantInfo> > CreateRestaurant([FromBody] RestaurantInfo restaurant)
        {
            if (restaurant == null)
            {
                return(BadRequest());
            }



            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (await _restaurantInfoRepository.RestaurantExists(restaurant.RestaurantId))
            {
                return(NotFound());
            }

            var finalRestaurant = _mapper.Map <RestaurantInfo>(restaurant);

            await _restaurantInfoRepository.AddRestaurant(restaurant);

            //_employeeInfoRepository.AddEmployee(employee);
            if (!await _restaurantInfoRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            var createdPointOfInterestToReturn = _mapper.Map <RestaurantDto>(finalRestaurant);

            return(CreatedAtAction("GetRestaurantById", new { id = createdPointOfInterestToReturn.RestaurantId }, createdPointOfInterestToReturn));
        }
Exemplo n.º 5
0
        public async Task <JsonResult> Info()
        {
            string emailAddress = HttpContext.User.Identity.Name;

            var restaurant = await _context.Restaurant
                             .Where(rest => rest.EmailAddress.Equals(emailAddress))
                             .FirstOrDefaultAsync();

            if (restaurant != null)
            {
                HttpContext.Response.StatusCode = 200;
                RestaurantInfo restaurantInfo = new RestaurantInfo();

                restaurantInfo.Name         = restaurant.Name;
                restaurantInfo.EmailAddress = restaurant.EmailAddress;
                restaurantInfo.Location     = restaurant.Location;
                restaurantInfo.PhoneNumber  = restaurant.PhoneNumber;
                restaurantInfo.HoursOpened  = restaurant.HoursOpened;

                return(new JsonResult(restaurantInfo));
            }
            else
            {
                HttpContext.Response.StatusCode = 401;
                return(new JsonResult("Not authorized"));
            }
        }
    protected void drpRestaurants_SelectedIndexChanged(object sender, EventArgs e)
    {
        //show the selected restaurant data as specified in the lab requirements

        if (drpRestaurants.SelectedValue != "-1")
        {
            string restaurantSelected = drpRestaurants.SelectedItem.Value;

            RestaurantReviewServiceClient reviewer = new RestaurantReviewServiceClient();
            RestaurantInfo rest = reviewer.GetRestaurantByName(restaurantSelected);

            txtAddress.Text       = rest.Location.Street;
            txtCity.Text          = rest.Location.City;
            txtProvinceState.Text = rest.Location.Province;
            txtPostalZipCode.Text = rest.Location.PostalCode;

            txtAddress.Enabled       = false;
            txtCity.Enabled          = false;
            txtProvinceState.Enabled = false;
            txtPostalZipCode.Enabled = false;

            txtSummary.Text           = rest.Summary;
            drpRating.SelectedValue   = rest.Rating.ToString();
            pnlViewRestaurant.Visible = true;
        }
        else
        {
            pnlViewRestaurant.Visible = false;
        }
    }
        public ActionResult UpdateReview(string restInfo)
        {
            if (!string.IsNullOrWhiteSpace(restInfo))
            {
                Models.RestaurantInfo restaurantInfo =
                    System.Web.Helpers.Json.Decode <Models.RestaurantInfo>(restInfo);

                RestaurantInfo info = new RestaurantInfo();
                info.Name    = restaurantInfo.Name;
                info.Summary = restaurantInfo.Summary;
                info.Rating  = restaurantInfo.Rating;

                info.Location            = new Address();
                info.Location.Street     = restaurantInfo.Location.Street;
                info.Location.City       = restaurantInfo.Location.City;
                info.Location.Province   = restaurantInfo.Location.Province;
                info.Location.PostalCode = restaurantInfo.Location.PostalCode;

                RestaurantReviewServiceClient reviewer = new RestaurantReviewServiceClient();
                if (reviewer.SaveRestaurant(info))
                {
                    return(Json("Updated restaurant review has been saved!"));
                }
            }
            return(Json("No data received!"));
        }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        //Save the changed restaurant restaurant data back to the XML file.

        RestaurantReviewServiceClient reviewer = new RestaurantReviewServiceClient();

        foreach (ListItem item in drpRestaurants.Items)
        {
            if (item.Selected == true && item.Value != "-1")
            {
                RestaurantInfo rest = reviewer.GetRestaurantByName(item.Value);

                rest.Summary = txtSummary.Text;
                Int32.TryParse(drpRating.SelectedValue, out int ratings);
                rest.Rating = ratings;
                if (reviewer.SaveRestaurant(rest))
                {
                    lblConfirmation.Text = "Revised restaurant has been saved to restaurant_reviews.xml";
                }
                else
                {
                    lblConfirmation.Text = "Save error";
                }
            }
        }
    }
        public async Task <ActionResult <RestaurantInfo> > PostRestaurantInfo(RestaurantInfo restaurantInfo)
        {
            _context.RestaurantInfo.Add(restaurantInfo);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRestaurantInfo", new { id = restaurantInfo.RestaurantId }, restaurantInfo));
        }
Exemplo n.º 10
0
 public static void SetUp(TestContext testContext)
 {
     dummy1 = new RestaurantInfo {
         Name = "McDonalds", Address = "65 Some Street", Rating = 2.8
     };
     dummy2 = new RestaurantInfo {
         Name = "Wendys", Address = "11 Apple Avenue", Rating = 3.6
     };
     dummy3 = new RestaurantInfo {
         Name = "Dunkin Donuts", Address = "23 America Drive Plaza", Rating = 3.5
     };;
     dummy4 = new RestaurantInfo {
         Name = "Subway", Address = "113 Benjamin Boulevard", Rating = 4.1
     };;
     dummy5 = new RestaurantInfo {
         Name = "Five Guys", Address = "211 Daytona Street", Rating = 4.8
     };;
     actualList1 = new List <RestaurantInfo> {
         dummy1, dummy2, dummy3, dummy4, dummy5
     };
     actualList2 = new List <RestaurantInfo> {
         dummy1, dummy2, dummy3, dummy4, dummy5
     };
     actualList3 = new List <RestaurantInfo> {
         dummy1, dummy2, dummy3, dummy4, dummy5
     };
 }
    protected void drpRestaurants_SelectedIndexChanged(object sender, EventArgs e)
    {
        //show the selected restaurant data as specified in the lab requirements
        lblConfirmation.Visible = false;

        string selectedRestaurant = null;

        selectedRestaurant = drpRestaurants.SelectedValue;

        RestaurantReviewServiceClient client = new RestaurantReviewServiceClient();

        RestaurantInfo restaurant = client.GetRestaurantByName(selectedRestaurant);


        if (selectedRestaurant == "0")
        {
            pnlViewRestaurant.Visible = false;

            txtAddress.Text = null;
            txtAddress.Attributes.Add("readonly", "readonly");

            txtCity.Text = null;
            txtCity.Attributes.Add("readonly", "readonly");

            txtProvinceState.Text = null;
            txtProvinceState.Attributes.Add("readonly", "readonly");

            txtPostalZipCode.Text = null;
            txtPostalZipCode.Attributes.Add("readonly", "readonly");

            txtSummary.Text = null;
            txtSummary.Attributes.Add("readonly", "readonly");

            drpRating.Style.Add("display", "none");
        }
        else
        {
            pnlViewRestaurant.Visible = true;

            txtAddress.Text = restaurant.Location.Street.ToString();
            txtAddress.Attributes.Add("readonly", "readonly");

            txtCity.Text = restaurant.Location.City.ToString();
            txtCity.Attributes.Add("readonly", "readonly");

            txtProvinceState.Text = restaurant.Location.Province.ToString();
            txtProvinceState.Attributes.Add("readonly", "readonly");

            txtPostalZipCode.Text = restaurant.Location.PostalCode.ToString();
            txtPostalZipCode.Attributes.Add("readonly", "readonly");

            txtSummary.Text = restaurant.Summary.ToString();
            txtSummary.Attributes.Remove("readonly");

            drpRating.Style.Remove("display");
            drpRating.SelectedValue = restaurant.Rating.ToString();
        }
    }
Exemplo n.º 12
0
        public void RestaurantInfoConstructorTest()
        {
            string expName     = "Marv's Pizza Palace";
            string expLocation = "789 Thisisa Street";

            RestaurantInfo testObj = new RestaurantInfo(expName, expLocation);

            Assert.AreEqual(expName, testObj.Name);
            Assert.AreEqual(expLocation, testObj.Location);
        }
Exemplo n.º 13
0
 public static void Map(ref Restaurant src, ref RestaurantInfo dst)
 {
     // TODO: implement map
     dst.Name         = src.Name;
     dst.Street       = src.Street;
     dst.City         = src.City;
     dst.State        = src.State;
     dst.Zipcode      = src.Zipcode;
     dst.RestaurantId = src.Id;
     dst.Country      = src.Country;
 }
    // 更新餐桌信息
    public static void UpdateDeskInfo(RestaurantInfo curRestaurant, GC_RESTAURANT_DESTUPDATE data)
    {
        int curDeskIndex = data.DestIndex;

        if (curDeskIndex >= curRestaurant.m_Desks.Length)
        {
            LogModule.ErrorLog("desk index is big than define " + curDeskIndex);
            return;
        }

        DeskInfo curDeskData = curRestaurant.m_Desks[curDeskIndex];

        curDeskData.m_IsActive  = true;
        curDeskData.m_DestState = (DeskState)data.DeskState;
        if (curDeskData.m_DestState == DeskState.EatFood)
        {
            for (int i = 0; i < data.deskGuestIDsCount; i++)
            {
                curDeskData.m_GuestIDs[i] = data.deskGuestIDsList[i];
            }
        }
        if (data.HasDeskFoodID)
        {
            curDeskData.m_FoodID = data.DeskFoodID;
        }
        else
        {
            curDeskData.m_FoodID = -1;
        }
        curDeskData.m_DeskFinishTime = (data.HasActionFinishTimer ? data.ActionFinishTimer : 0) + (int)Time.realtimeSinceStartup;
        int nRestaurantTipCount = 0;

        for (int i = 0; i < m_PlayerRestaurantInfo.m_Desks.Length; i++)
        {
            DeskInfo oDeskData = m_PlayerRestaurantInfo.m_Desks[i];
            if (oDeskData.m_IsActive && oDeskData.m_DestState == DeskState.WaitBilling)
            {
                nRestaurantTipCount++;
            }
        }
        if (!data.HasFriendGuid)
        {
            m_restaurantTipsCount = nRestaurantTipCount;

            if (MenuBarLogic.Instance() != null)
            {
                MenuBarLogic.Instance().UpdateRestaurantTips();
            }
            if (PlayerFrameLogic.Instance() != null)
            {
                PlayerFrameLogic.Instance().UpdateRemainNum();
            }
        }
    }
Exemplo n.º 15
0
        public void SubmitReviewTest()
        {
            string         expReviewerName = "Hanzo Lastname";
            int            expRating       = 4;
            string         expDesc         = "";
            RestaurantInfo rest            = new RestaurantInfo("name", "loc");

            rest.SubmitReview(expReviewerName, expRating);

            Assert.IsTrue(rest.ReviewCount > 0);
        }
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Error"));
            }
            RestaurantReviewServiceClient reviewService = new RestaurantReviewServiceClient();
            RestaurantInfo restInfo = reviewService.GetRestaurantById(id.Value);

            return(View(restInfo));
        }
Exemplo n.º 17
0
        public void TestRepoDependencyInjection()
        {
            var restRepo   = new Mock <IRestaurantRepository>();
            var reviewRepo = new Mock <IReviewerRepository>();

            restRepo.Setup(i => i.GetRestaurantById(34)).Returns(new RestaurantInfo(34, "repoTest", "test city", "test street", "descrip", "testemail"));
            var sut      = new RestaurantService(restRepo.Object, reviewRepo.Object);
            var expected = new RestaurantInfo(34, "repoTest", "test city", "test street", "descrip", "testemail");
            var actual   = sut.GetRestaurantById(34);

            Assert.AreEqual(expected, actual, "Nope");
        }
Exemplo n.º 18
0
        private RestaurantInfo createNewRestaurnatInfoAndSave()
        {
            var filePath = getFilePath();
            var rsi      = new RestaurantInfo();

            rsi.Name    = "Your Restaurant Name";
            rsi.Phone   = "Your Number Phone";
            rsi.Address = "Your Address";
            rsi.Path    = "";
            save(rsi);
            return(rsi);
        }
Exemplo n.º 19
0
        private static RestaurantInfo ToDB(Restaurant r)
        {
            RestaurantInfo rInfo = new RestaurantInfo
            {
                id      = r.id,
                Name    = r.Name,
                Address = r.Address,
                Image   = r.Image
            };

            return(rInfo);
        }
Exemplo n.º 20
0
        public void RestaurantInfoGetAverageRatingTest1()
        {
            string         expName     = "Tatsuya Ramen";
            string         expLocation = "123 Fake St.";
            double         expRating   = 0.0;
            RestaurantInfo testObj     = new RestaurantInfo(expName, expLocation);

            double actualVal = testObj.GetAverageRating;

            Assert.AreEqual(expName, testObj.Name);
            Assert.AreEqual(expLocation, testObj.Location);
            Assert.AreEqual(expRating, actualVal);
        }
Exemplo n.º 21
0
        public void TestRestAdd()
        {
            var            restRepo   = new Mock <IRestaurantRepository>();
            var            reviewRepo = new Mock <IReviewerRepository>();
            var            service    = new RestaurantService(restRepo.Object, reviewRepo.Object);
            RestaurantInfo dummyRest  = new RestaurantInfo(34, "repoTest", "test city", "test street", "descrip", "testemail");

            restRepo.Setup(i => i.AddRestaurant(new RestaurantInfo(34, "repoTest", "test city", "test street", "descrip", "testemail"))).Returns(true);
            var expected = true;
            var actual   = service.AddRestaurant(dummyRest);

            Assert.AreEqual(expected, actual, "Delete failed");
        }
Exemplo n.º 22
0
        protected void btEdit_Click(object sender, EventArgs e)
        {
            RestaurantInfo    _Res    = new RestaurantInfo();
            RestaurantInfoBLL _ResBLL = new RestaurantInfoBLL();


            _Res.Introduction = this.TxtResIntroduce.Text.Trim();
            _Res.Local        = this.TxtResLoc.Text.Trim();
            _Res.OpenTime     = this.txtOpenTime.Text.Trim();
            _Res.PhoneNum     = this.TxtResNum.Text.Trim();

            if (this.txtResLgt.Text.Trim() != "")
            {
                _Res.SLongitude = float.Parse(txtResLgt.Text.Trim().ToString());
            }
            else
            {
                _Res.SLongitude = 0.0f;
            }

            if (this.txtResLat.Text.Trim() != "")
            {
                _Res.SLongitude = float.Parse(txtResLat.Text.Trim().ToString());
            }
            else
            {
                _Res.Slatitude = 0.0f;
            }

            if (Request.QueryString["CityID"] != null)
            {
                CityID = int.Parse(Request.QueryString["CityID"].ToString());
            }
            if (Request.QueryString["CityName"] != null)
            {
                CityName = Request.QueryString["CityName"].ToString();
            }
            if (Request.QueryString["PageStart"] != null)
            {
                PageStart = int.Parse(Request.QueryString["PageStart"].ToString());
            }
            int ResID = int.Parse(Request.QueryString["RestaurantID"].ToString());

            if (_ResBLL.UpdResInfo(ResID, _Res))
            {
                Response.Write("<script language='javascript'>");
                Response.Write("alert('更新成功');");
                Response.Write("document.location.href='ResInfoList.aspx?&CityID=" + CityID.ToString() + "&CityName=" + CityName + "&PageStart=" + PageStart.ToString() + "';");
                Response.Write("</script>");
            }
        }
Exemplo n.º 23
0
        public bool DeleteRestaurant(RestaurantInfo restaurant)
        {
            try
            {
                _context.RestaurantInfoes.Remove(restaurant);
                _context.SaveChanges();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 24
0
        public bool AddRestaurant(RestaurantInfo restaurant)
        {
            try
            {
                _context.RestaurantInfoes.Add(restaurant);
                _context.SaveChanges();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
        public IActionResult Edit(RestaurantInfo restInfo)
        {
            RestaurantReviewServiceClient reviewService = new RestaurantReviewServiceClient();

            try
            {
                reviewService.SaveRestaurant(restInfo);
            }
            catch (Exception e)
            {
                return(RedirectToAction("Error on Edit"));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 26
0
        public void GetAllReviewsTest1()
        {
            string         expName     = "Restaurant1";
            string         expLocation = "123 One St.";
            RestaurantInfo rest        = new RestaurantInfo(expName, expLocation);

            var l = rest.GetAllReviews();

            foreach (var review in l)
            {
                Assert.Fail();
            }
            Assert.IsTrue(l.Count() == 0);
        }
Exemplo n.º 27
0
        private static Restaurant ToWeb(RestaurantInfo rInfo)
        {
            Restaurant r = new Restaurant
            {
                id      = rInfo.id,
                Name    = rInfo.Name,
                Address = rInfo.Address,
                Rating  = rInfo.Rating,
                Image   = rInfo.Image,
                //Reviews = rInfo.Reviews.Cast<Review>().ToList()
            };

            return(r);
        }
Exemplo n.º 28
0
        public RestaurantInfo GetRestaurantById(int id)
        {
            List <RestaurantInfo> allOfThem = new List <RestaurantInfo>();

            Restaurants allRestaurantXml = GetRestaurantReviewsFromXml();

            int Id = 0;

            foreach (var item in allRestaurantXml.Restaurant)
            {
                RestaurantInfo newRestaurant = new RestaurantInfo();
                Address        newAddress    = new Address();
                Id = Id + 1;

                newAddress.city       = item.Address.city;
                newAddress.address    = item.Address.address;
                newAddress.postalcode = item.Address.postalcode;
                newAddress.province   = item.Address.province;

                newRestaurant.Id      = Id;
                newRestaurant.Name    = item.Name;
                newRestaurant.Food    = item.Food;
                newRestaurant.Summary = item.Summary;
                newRestaurant.Rating  = item.Rating.Value;
                newRestaurant.Price   = item.Price.Value;

                newRestaurant.address = newAddress;
                allOfThem.Add(newRestaurant);
            }

            RestaurantInfo theRestaurant = new RestaurantInfo();

            foreach (var item in allOfThem)
            {
                if (item.Id == id)
                {
                    theRestaurant.Id      = item.Id;
                    theRestaurant.Name    = item.Name;
                    theRestaurant.Food    = item.Food;
                    theRestaurant.Summary = item.Summary;
                    theRestaurant.Rating  = item.Rating;
                    theRestaurant.Price   = item.Price;
                    theRestaurant.address = item.address;
                }
            }
            Id = 0;

            return(theRestaurant);
        }
Exemplo n.º 29
0
        public async Task <JsonResult> Edit([FromBody] RestaurantInfo restaurantInfo)
        {
            string emailAddress = HttpContext.User.Identity.Name;

            var restaurant = await _context.Restaurant
                             .Where(rest => rest.EmailAddress.Equals(emailAddress))
                             .FirstOrDefaultAsync();

            if (RestaurantNameExists(restaurantInfo.Name, emailAddress))
            {
                HttpContext.Response.StatusCode = 400;
                return(new JsonResult("Restaurant name " + restaurantInfo.Name + " already exists"));
            }
            else if (RestaurantEmailAddressExists(restaurantInfo.EmailAddress, emailAddress))
            {
                HttpContext.Response.StatusCode = 400;
                return(new JsonResult("Restaurant email address " + restaurantInfo.EmailAddress + " already exists"));
            }

            // set fields
            restaurant.Name         = restaurantInfo.Name;
            restaurant.EmailAddress = restaurantInfo.EmailAddress;
            restaurant.Location     = restaurantInfo.Location;
            restaurant.PhoneNumber  = restaurantInfo.PhoneNumber;
            restaurant.HoursOpened  = restaurantInfo.HoursOpened;

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(restaurant);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RestaurantExists(restaurant.Id))
                    {
                        return(new JsonResult(""));
                    }
                    else
                    {
                        throw;
                    }
                }
                HttpContext.Response.StatusCode = 200;
            }

            return(new JsonResult("Restaurant data successfully updated."));
        }
Exemplo n.º 30
0
        public List <RestaurantInfo> GetAllRestaurants()
        {
            Restaurants           reviews   = GetRestaurantReviewsFromXml();
            List <RestaurantInfo> restInfos = new List <RestaurantInfo>();
            int id = 0;

            foreach (RestaurantsRestaurant rest in reviews.Restaurant)
            {
                RestaurantInfo restInfo = GetRestaurantInfo(rest);
                restInfo.Id = id;
                restInfos.Add(restInfo);
                id++;
            }
            return(restInfos);
        }
 public AddRestaurant(RestaurantInfo restaurant)
 {
     this.Restaurant = restaurant;
 }
 public GetRestaurantsResponse(RestaurantInfo[] restaurants)
 {
     this.Restaurants = restaurants;
 }