コード例 #1
0
        public ActionResult Login(Login user, string checkbox)
        {
            //user se spaja preko name taga

            RestaurantsUserCombo combo = WebApiApplication.BackendPostWithReturn <Login, RestaurantsUserCombo>(user, WebApiApplication.URL_LOGIN_PATH);

            //string test = combo.WebUser.Username;

            if (combo.WebUser == null)
            {
                return(View("Login"));
            }
            WebApiApplication.restaurants = combo.RestaurantModels;

            Session["username"] = combo.WebUser.Username;
            if (combo.WebUser.VIDs == null)
            {
                Session["VIDs"] = String.Empty;
            }
            else
            {
                Session["VIDs"] = combo.WebUser.VIDs;
            }


            //List<Food> hrana = new List<Food>();
            //hrana.Add(new Food("Jetrica", new GradeSpread(1, 2, 3, 4, 5), 30.99, "https://hmdk.hr/wp-content/uploads/2019/02/15.jpg", 11));
            //hrana.Add(new Food("Juha", new GradeSpread(1, 2, 3, 4, 5), 343.2, "https://hmdk.hr/wp-content/uploads/2019/02/15.jpg", 12));
            //hrana.Add(new Food("Špageti", new GradeSpread(1, 2, 3, 4, 5), 342, "https://hmdk.hr/wp-content/uploads/2019/02/15.jpg", 13));
            //hrana.Add(new Food("Sarma", new GradeSpread(1, 2, 3, 4, 5), 10.15, "https://hmdk.hr/wp-content/uploads/2019/02/15.jpg", 14));
            //hrana.Add(new Food("Riba", new GradeSpread(1, 2, 3, 4, 5), 3.2, "https://hmdk.hr/wp-content/uploads/2019/02/15.jpg", 15));
            //List<Wine> vina = new List<Wine>();
            //vina.Add(new Wine("Graševina", new GradeSpread(1, 2, 3, 4, 5), 3.2, "https://img.etimg.com/thumb/msid-44856181,width-1200,height-900,imgsize-95099,overlay-etpanache/photo.jpg", 21));
            //vina.Add(new Wine("Hrnjevac", new GradeSpread(1, 2, 3, 4, 5), 3.2, "https://img.etimg.com/thumb/msid-44856181,width-1200,height-900,imgsize-95099,overlay-etpanache/photo.jpg", 22));
            //vina.Add(new Wine("Pinot", new GradeSpread(1, 2, 3, 4, 5), 3.2, "https://img.etimg.com/thumb/msid-44856181,width-1200,height-900,imgsize-95099,overlay-etpanache/photo.jpg", 23));
            //vina.Add(new Wine("Plavac", new GradeSpread(1, 2, 3, 4, 5), 3.2, "https://img.etimg.com/thumb/msid-44856181,width-1200,height-900,imgsize-95099,overlay-etpanache/photo.jpg", 24));
            //GradeSpread gradeSpread = new GradeSpread(20, 6, 15, 63, 150);
            ////GradeSpread gradeSpread = new GradeSpread(0, 0, 0, 0, 0);
            //string opis = "Ovaj restoran ima najukusniju hranu, najbolja vina, i predivnu atmosferu";


            //RestaurantModel restaurant1 = new RestaurantModel("drugi sadfa", opis, hrana, vina, gradeSpread, "https://www.visit-pag.com/photos/tours/thumbs/restaurant-amare-5e03403b1fa96935512841_huge.jpg",3);
            //RestaurantModel restaurant2 = new RestaurantModel("treći", opis, hrana, vina, gradeSpread, "https://www.visit-pag.com/photos/tours/thumbs/restaurant-amare-5e03403b1fa96935512841_huge.jpg",4);
            //RestaurantModel restaurant3 = new RestaurantModel("četvrti", opis, hrana, vina, gradeSpread, "https://www.visit-pag.com/photos/tours/thumbs/restaurant-amare-5e03403b1fa96935512841_huge.jpg",5);
            //RestaurantModel restaurant4 = new RestaurantModel("peti", opis, hrana, vina, gradeSpread, "https://www.visit-pag.com/photos/tours/thumbs/restaurant-amare-5e03403b1fa96935512841_huge.jpg",6);
            //RestaurantModel restaurant5 = new RestaurantModel("šesti",opis, hrana, vina, gradeSpread, "https://www.visit-pag.com/photos/tours/thumbs/restaurant-amare-5e03403b1fa96935512841_huge.jpg",7);
            //RestaurantModel restaurant6 = new RestaurantModel("sedmi",opis, hrana, vina, gradeSpread, "https://www.visit-pag.com/photos/tours/thumbs/restaurant-amare-5e03403b1fa96935512841_huge.jpg",8);
            //RestaurantModel restaurant7 = new RestaurantModel("osmi",opis, hrana, vina, gradeSpread, "https://www.visit-pag.com/photos/tours/thumbs/restaurant-amare-5e03403b1fa96935512841_huge.jpg",9);
            //RestaurantModel restaurant8 = new RestaurantModel("deveti",opis, hrana, vina, gradeSpread, "https://www.visit-pag.com/photos/tours/thumbs/restaurant-amare-5e03403b1fa96935512841_huge.jpg",10);
            //WebApiApplication.restaurants.Add(restaurant1);
            //WebApiApplication.restaurants.Add(restaurant2);
            //WebApiApplication.restaurants.Add(restaurant3);
            //WebApiApplication.restaurants.Add(restaurant4);
            //WebApiApplication.restaurants.Add(restaurant5);
            //WebApiApplication.restaurants.Add(restaurant6);
            //WebApiApplication.restaurants.Add(restaurant7);
            //WebApiApplication.restaurants.Add(restaurant8);

            WebApiApplication.filteredRestaurants = WebApiApplication.restaurants;

            if (checkbox == "on")
            {
                Response.Cookies.Add(new HttpCookie("Username", user.Username));
                Response.Cookies.Add(new HttpCookie("Password", user.Password));
                Response.Cookies["Username"].Expires = DateTime.Now.AddMinutes(5);
                Response.Cookies["Password"].Expires = DateTime.Now.AddMinutes(5);

                //Response.Cookies["Username"].Value = user.Username;
                //Response.Cookies["Password"].Value = user.Password;
            }


            WebApiApplication.LOGED_IN = true;
            return(RedirectToAction("Index", "Home"));
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: Krexy/OICAR
        public ActionResult UpdateGrade(string RestaurantName, int rVID)
        {
            string          currentUser = Session["username"] as String;
            RestaurantModel model       = WebApiApplication.restaurants.Where(r => r.RestaurantName == RestaurantName).FirstOrDefault();


            //StringBuilder stringBuilder = new StringBuilder();
            //int postfix = 1;
            //    //umjesto 4 napisi listu hrane iz restorana
            //    for (int i = 0; i < 4; i++)
            //    {
            //        for (int j = 0; j < 5; j++)
            //        {
            //            stringBuilder.Append(Request.Form["cbf" + postfix.ToString()]);
            //            if (!(i == 3 && j == 4))
            //            {
            //                stringBuilder.Append(",");
            //            }
            //            postfix++;
            //        }
            //    }
            bool rest = SetRestaurantGradeSpread("cbr", model);
            List <GradeSpread> FGradeSpread = GetGradeSpread("cbf", model);
            List <GradeSpread> WGradeSpread = GetGradeSpread("cbw", model);


            List <string> vidslist = new List <string>();
            //if (rVID != -1)
            //{
            //    vidslist.Add(rVID.ToString());

            //}
            int Fcounter = 0;

            if (FGradeSpread != null)
            {
                foreach (var food in FGradeSpread)
                {
                    model.Food[Fcounter].Grade.One   += food.One;
                    model.Food[Fcounter].Grade.Two   += food.Two;
                    model.Food[Fcounter].Grade.Three += food.Three;
                    model.Food[Fcounter].Grade.Four  += food.Four;
                    model.Food[Fcounter].Grade.Five  += food.Five;
                    if (!(food.Five == 0 && food.Four == 0 && food.Three == 0 && food.Two == 0 && food.One == 0))
                    {
                        vidslist.Add(model.Food[Fcounter].VID.ToString());
                    }
                    Fcounter++;
                }
            }

            int Wcounter = 0;

            if (WGradeSpread != null)
            {
                foreach (var wine in WGradeSpread)
                {
                    model.Wine[Wcounter].Grade.One   += wine.One;
                    model.Wine[Wcounter].Grade.Two   += wine.Two;
                    model.Wine[Wcounter].Grade.Three += wine.Three;
                    model.Wine[Wcounter].Grade.Four  += wine.Four;
                    model.Wine[Wcounter].Grade.Five  += wine.Five;
                    if (!(wine.Five == 0 && wine.Four == 0 && wine.Three == 0 && wine.Two == 0 && wine.One == 0))
                    {
                        vidslist.Add(model.Wine[Wcounter].VID.ToString());
                    }
                    Wcounter++;
                }
            }
            string finalVIDS = rest == true?rVID.ToString() + "," : String.Empty;

            //vidslist.ForEach(v=>finalVIDS.Join(",",v.ToString()));
            foreach (var v in vidslist)
            {
                //if (finalVIDS == String.Empty)
                //{
                //    finalVIDS += v.ToString() + ",";

                //}
                //else
                //{
                //    finalVIDS += v.ToString() + ",";
                //}
                finalVIDS += v.ToString() + ",";
            }
            if (Session["VIDs"] as String != String.Empty)
            {
                finalVIDS = Session["VIDs"] as String + "," + finalVIDS;
            }
            if (finalVIDS.Length > 0)
            {
                finalVIDS = finalVIDS.Remove(finalVIDS.Length - 1);
            }
            Session["VIDs"] = finalVIDS;
            //string test = Session["VIDs"] as String;

            RestaurantUserCombo restaurantUserCombo = new RestaurantUserCombo()
            {
                RestaurantModel = model, WebUser = new WebUser()
                {
                    Username = currentUser, VIDs = finalVIDS
                }
            };

            //string xmlPath = ControllerContext.HttpContext.Server.MapPath("~/example.xml");

            RestaurantsUserCombo restaurantsUserCombo = WebApiApplication.BackendPostWithReturn <RestaurantUserCombo, RestaurantsUserCombo>(restaurantUserCombo, WebApiApplication.URL_GRADE_UPDATE_PATH);

            Session["username"]                   = restaurantsUserCombo.WebUser.Username;
            WebApiApplication.restaurants         = restaurantsUserCombo.RestaurantModels;
            WebApiApplication.filteredRestaurants = WebApiApplication.restaurants;

            HelperModel helperModel = WebApiApplication.currentHelperModel;

            helperModel.RestaurantModel = model;
            if (finalVIDS != String.Empty)
            {
                List <String> VIDstrings = finalVIDS.Split(',').ToList();
                VIDstrings.ForEach(v => helperModel.VIDs.Add(int.Parse(v)));
            }

            return(View("RestaurantDetails", helperModel));
        }