public bool Update(RestaurantProfileVM profile) { Restaurant restaurant = db.Restaurant .Where(r => r.UserId == profile.UserId) .FirstOrDefault(); if (restaurant == null) { restaurant = new Restaurant(); db.Add(restaurant); db.SaveChanges(); } restaurant.UserId = profile.UserId; restaurant.Name = profile.Name; restaurant.PriceCategory = profile.PriceCategory; restaurant.Url = profile.Url; restaurant.StreetAddress = profile.StreetAddress; restaurant.City = profile.City; restaurant.PostalCode = profile.PostalCode; db.SaveChanges(); foreach (var checkbox in profile.FoodCategoryCheckboxes) { if (checkbox.IsChecked) { RestaurantFoodCategory entry = new RestaurantFoodCategory() { FoodCategoryId = checkbox.ID, RestaurantId = restaurant.Id }; db.Add(entry); db.SaveChanges(); } else { ICollection <RestaurantFoodCategory> entries = db.RestaurantFoodCategory .Where(f => f.RestaurantId == restaurant.Id && f.FoodCategoryId == checkbox.ID) .Distinct().ToList(); foreach (var entry in entries) { db.RestaurantFoodCategory.Remove(entry); db.SaveChanges(); } } } PriceCategoryDropdownBuilder helper = new PriceCategoryDropdownBuilder(); profile.PriceCategory = helper.convertType(profile.PriceCategoryString); if (profile.PriceCategory != null) { restaurant.PriceCategory = profile.PriceCategory; db.SaveChanges(); } return(true); }
public IActionResult Create(UserProfileVM upvm) { AspNetUsers aspuser = new AspNetUsers { UserName = upvm.aspNetUsers.UserName }; RestaurantGoer rg = new RestaurantGoer { Name = upvm.restaurantGoer.Name, PriceCategory = upvm.restaurantGoer.PriceCategory }; db.SaveChanges(); return(RedirectToAction("Index", upvm.aspNetUsers.Id)); }
public bool Update(string id, UserProfileVM upVM) { RestaurantGoer restaurantGoer = db.RestaurantGoer .Where(r => r.UserId == id) .FirstOrDefault(); if (restaurantGoer != null) { restaurantGoer.Name = upVM.Name; //restaurantGoer.PriceCategory = upVM.price_category; restaurantGoer.UserId = id; db.SaveChanges(); } else { RestaurantGoer restaurantGoers = new RestaurantGoer(); restaurantGoers.UserId = id; restaurantGoers.Name = upVM.Name; //restaurantGoers.PriceCategory = upVM.price_category; db.Add(restaurantGoers); db.SaveChanges(); } var restaurantgoerId = db.RestaurantGoer .Where(r => r.UserId == id) .FirstOrDefault(); var foodCategoryId = db.FoodCategory .Where(f => f.Name == upVM.foodCategoryName) .FirstOrDefault(); //RestaurantGoerFoodCategory restaurantGoerFoodCategory = new RestaurantGoerFoodCategory(); //restaurantGoerFoodCategory.FoodCategoryId = foodCategoryId.Id; //restaurantGoerFoodCategory.RestaurantGoerId = restaurantgoerId.Id; //db.Add(restaurantGoerFoodCategory); //db.SaveChanges(); var restaurantId = db.Restaurant .Where(r => r.Name == upVM.RestaurantName) .FirstOrDefault(); RestaurantGoerRestaurant restaurantGoerRestaurant = new RestaurantGoerRestaurant(); restaurantGoerRestaurant.RestaurantGoerId = restaurantgoerId.Id; restaurantGoerRestaurant.RestaurantId = restaurantId.Id; db.Add(restaurantGoerRestaurant); db.SaveChanges(); foreach (var checkbox in upVM.FoodCategoryCheckboxes) { if (checkbox.IsChecked) { RestaurantGoerFoodCategory entry = new RestaurantGoerFoodCategory() { FoodCategoryId = checkbox.ID, RestaurantGoerId = restaurantGoer.Id }; db.Add(entry); db.SaveChanges(); } else { ICollection <RestaurantGoerFoodCategory> entries = db.RestaurantGoerFoodCategory .Where(f => f.RestaurantGoerId == restaurantGoer.Id && f.FoodCategoryId == checkbox.ID) .Distinct().ToList(); foreach (var entry in entries) { db.RestaurantGoerFoodCategory.Remove(entry); db.SaveChanges(); } } } PriceCategoryDropdownBuilder helper = new PriceCategoryDropdownBuilder(); upVM.PriceCategory = helper.convertType(upVM.PriceCategoryString); if (upVM.PriceCategory != null) { restaurantGoer.PriceCategory = upVM.PriceCategory; db.SaveChanges(); } return(true); }
public void CreateNewPlateTime(PlateTime plateTime) { db.Add(plateTime); db.SaveChanges(); }