internal static RestaurantsUserCombo GradeRestaurant(RestaurantUserCombo restaurantUserCombo) { RestaurantsUserCombo restaurantsUserCombo = new RestaurantsUserCombo(); using (RestaurantContext dbr = new RestaurantContext()) { foreach (var item in dbr.RestaurantOwners.Include("Restaurant.Grade").Include("Restaurant.Wine.Grade").Include("Restaurant.Food.Grade")) { if (item.Restaurant.VID == restaurantUserCombo.RestaurantModel.VID) { item.Restaurant = restaurantUserCombo.RestaurantModel; } } List <RestaurantModel> rm = new List <RestaurantModel>(); foreach (var item in dbr.RestaurantOwners.Include("Restaurant.Grade").Include("Restaurant.Wine.Grade").Include("Restaurant.Food.Grade")) { rm.Add(item.Restaurant); } foreach (var item in dbr.WebUsers) { if (item.Username.Equals(restaurantUserCombo.WebUser.Username)) { item.VIDs = restaurantUserCombo.WebUser.VIDs; restaurantsUserCombo.WebUser = item; } } restaurantsUserCombo.RestaurantModels = rm; dbr.SaveChanges(); return(restaurantsUserCombo); } }
public RestaurantsUserCombo Grade([FromBody] RestaurantUserCombo restaurantUserCombo) { return(DBLogic.GradeRestaurant(restaurantUserCombo)); }
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)); }