public async Task <bool> AddItemAsync(StolyBackup item) { await RestContext.Stolies.AddAsync(item); RestContext.SaveChanges(); return(await Task.FromResult(true)); }
public IHttpActionResult CreateMe(restDto RestDto) { if (!ModelState.IsValid) { return(BadRequest()); } var rinfo = Mapper.Map <restDto, rest>(RestDto); Context.rests.Add(rinfo); Context.SaveChanges(); RestDto.id = rinfo.id; return(Created(new Uri(Request.RequestUri + "/" + rinfo.id), RestDto)); }
public IActionResult addReviews(ReviewViewModel model) { List <string> errors = new List <string>(); if (DateTime.Now >= model.Date_Visited && ModelState.IsValid) { Reviews newReview = new Reviews { Reviewer_Name = model.Reviewer_Name, Restaurant_Name = model.Restaurant_Name, Review = model.Review, Date_Visited = model.Date_Visited, Stars = model.Stars, created_at = DateTime.Now, updated_at = DateTime.Now }; _context.Reviews.Add(newReview); _context.SaveChanges(); return(RedirectToAction("showReviews")); } else { errors = ModelState.Select(x => x.Value.Errors) .Where(y => y.Count > 0) .Select(z => z[0].ErrorMessage.ToString()) .ToList(); } if (DateTime.Now <= model.Date_Visited) { errors.Add("Cannot be in the future!"); } TempData["error_list"] = errors; return(RedirectToAction("Index")); }
public IActionResult CreateReview(Review review) { review.CreatedAt = DateTime.Now; review.UpdatedAt = DateTime.Now; _context.Add(review); _context.SaveChanges(); return(RedirectToAction("Reviews")); }
public IActionResult addReview(Rest rest) { if (ModelState.IsValid) { _context.Add(rest); _context.SaveChanges(); return(RedirectToAction("showreviews")); } return(View("Index")); }
public IActionResult Add(Review r) { if (ModelState.IsValid) { _context.Add(r); _context.SaveChanges(); return(RedirectToAction("ShowReviews")); } return(View("Index")); }
public IActionResult createReview(Rest newRest) { if (ModelState.IsValid) { _context.Add(newRest); _context.SaveChanges(); return(RedirectToAction("Review")); } return(View("Index")); }
public IActionResult Create(Reviews review) { if (ModelState.IsValid) { _context.Add(review); _context.SaveChanges(); return(RedirectToAction("Result")); } else { return(View("Index")); } }
public IActionResult Process(Review newReview) { if (ModelState.IsValid) { _context.Add(newReview); _context.SaveChanges(); return(RedirectToAction("Reviews")); } else { ViewBag.errors = ModelState.Values; return(View("Index")); } }
public RestController(RestContext context) { _context = context; if (_context.DishItems.Count() == 0) { _context.DishItems.Add(new DishItem { Name = "Суп", Description = "Вкусный", Price = 100 }); _context.DishItems.Add(new DishItem { Name = "Лапша", Description = "Сытная", Price = 199 }); _context.SaveChanges(); } }
public IActionResult CreateReview(Review review) { if (ModelState.IsValid) { System.Console.WriteLine(review); review.created_at = DateTime.Now; review.updated_at = DateTime.Now; _context.Add(review); _context.SaveChanges(); return(RedirectToAction("Reviews")); } System.Console.WriteLine("ERRORS!"); return(View("Index")); }
public IActionResult AddReview(Review newreview) { Review test = newreview; if (ModelState.IsValid) { if (newreview.date_of_visit > DateTime.Now) { ViewBag.error = "Cannot review a future visit"; return(RedirectToAction("Index")); } _context.Add(newreview); _context.SaveChanges(); return(RedirectToAction("Reviews")); } return(View("Index", newreview)); }
public IHttpActionResult PostFatura(Fatura fatura) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Faturas.Add(fatura); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = fatura.FaturaID }, fatura)); }
public IActionResult AddReview(User user) { if (user.Date > DateTime.Now) { ModelState.AddModelError("Date", "Visit must be in the past."); } if (ModelState.IsValid) { _context.Add(user); _context.SaveChanges(); return(RedirectToAction("Review")); } else { ViewBag.errors = ModelState.Values; return(View("Index")); } }
public IActionResult Review(Review NewReview) { if (ModelState.IsValid) { _context.Add(NewReview); _context.SaveChanges(); TempData["message"] = "You successfully made a review!"; return(RedirectToAction("Reviews")); } // TempData["message"] = "You're missing some information!"; else { // TempData["errors"] = ModelState.Values; // System.Console.WriteLine(ModelState.Values); ViewBag.Errors = ModelState.Values; } return(View("Index")); // return RedirectToAction("Index"); }
public IActionResult Create(REST rest) { // REST NewRest = new REST // { // Name = rest.Name, // Restaurant = rest.Restaurant, // Review = rest.Review, // Rate = rest.Rate, // Visit = rest.Visit // }; if (ModelState.IsValid) { _context.Add(rest); _context.SaveChanges(); return(RedirectToAction("Reviews")); } return(RedirectToAction("Index", rest)); }
public IActionResult AddReview(Review NewReview) { if (ModelState.IsValid) { _context.Add(NewReview); _context.SaveChanges(); return(RedirectToAction("Reviews")); } List <string> allErrors = new List <string>(); foreach (var i in ModelState.Values) { if (i.Errors.Count > 0) { allErrors.Add(i.Errors[0].ErrorMessage.ToString()); } } TempData["Errors"] = allErrors; return(RedirectToAction("Index")); }
public IActionResult AddReview(Review NewReview) { if (ModelState.IsValid) { System.Console.WriteLine($"Model is Valid {NewReview}."); NewReview.CreatedAt = DateTime.Now; NewReview.UpdatedAt = DateTime.Now; _context.Add(NewReview); _context.SaveChanges(); //add and commit return(RedirectToAction("Show")); } else { System.Console.WriteLine("Model is NOT Valid"); return(View("Index")); } // System.Console.WriteLine(NewReview); // _context.Add(NewReview); // _context.SaveChanges(); // return RedirectToAction("Results"); }
public IActionResult NewReview(Review review) { Review addReview = new Review { Reviewer = review.Reviewer, Restaurant = review.Restaurant, Stars = review.Stars, Reviews = review.Reviews, Visit_Date = review.Visit_Date, Created_At = DateTime.Now, Updated_At = DateTime.Now, }; TryValidateModel(addReview); if (ModelState.IsValid) { _context.Add(addReview); _context.SaveChanges(); return(RedirectToAction("Home")); } ViewBag.errors = ModelState.Values; return(View("Index")); }
/// <summary> /// Gets all the challenges the user has done. It can be that the user skipped days. /// </summary> /// <returns>Challenge data</returns> public IEnumerable <object> GetChallenges() { var acceptLanguages = Request.Headers.AcceptLanguage.FirstOrDefault(); string language = acceptLanguages == null ? "nl-BE" : acceptLanguages.Value; var challenges = User.Challenges; // challenges.ToList().ForEach(c => _languageProvider.Register(c)); foreach (Challenge c in challenges) { if (c.Thumbnail == null) { if (c is CreativeCookingChallenge) { c.Thumbnail = (c as CreativeCookingChallenge).Recipe.Image; _context.SaveChanges(); } else if (c is RecipeChallenge) { c.Thumbnail = (c as RecipeChallenge).Recipe.Image; _context.SaveChanges(); } } } // _languageProvider.Translate(language); return(challenges.Select(c => new { ChallengeId = c.ChallengeId, Date = c.Date, Done = c.Done, Name = c.Name, Earnings = c.Earnings, Type = c.Type, Thumbnail = c.Thumbnail, ExpireDate = c.ExpireDate, TimeToAccept = c.TimeToAccept // Rt = ((c is RecipeChallenge) ? (c as RecipeChallenge).Recipe.Properties.Any(p => p.Type.Equals("Regio")) : false) })); }
// GET: Filler public IHttpActionResult Index() { string filename = @"C:\Users\Jasper De Vrient\Documents\Tin3\Project III\ApiBackEnd\EVARest\EVARest\recepten.json"; IDictionary <string, RecipeProperty> properties = new Dictionary <string, RecipeProperty>(); IDictionary <string, Ingredient> ingredients = new Dictionary <string, Ingredient>(); IList <Recipe> recipeObjects = new List <Recipe>(); const string r_prop = "properties"; const string r_title = "title"; const string r_image = "image"; const string r_description = "description"; const string r_ingredients = "ingredients"; const string c_ingredient = "ingredient"; const string i_name = "name"; const string i_prefix = "prefix"; const string i_postfix = "postfix"; int successes = 0; int failures = 0; using (StreamReader file = File.OpenText(filename)) using (JsonTextReader reader = new JsonTextReader(file)) { JArray recepten = (JArray)JToken.ReadFrom(reader); Console.WriteLine($"{recepten.Count} Recepten gelezen uit json."); foreach (JObject recipeJson in recepten) { try { Recipe r = new Recipe(); r.Name = recipeJson[r_title].ToString(); r.Image = recipeJson[r_image].ToString(); r.Description = recipeJson[r_description].ToString(); foreach (JObject component in recipeJson[r_ingredients]) { Component c = new Component(); int amount = 0; // if (int.TryParse(component[c_count].ToString(), out amount)) c.Prefix = component[c_ingredient][i_prefix].ToString(); c.Postfix = component[c_ingredient][i_postfix].ToString(); var iname = component[c_ingredient][i_name].ToString(); if (!ingredients.ContainsKey(iname)) { Ingredient i = new Ingredient(); i.Name = component[c_ingredient][i_name].ToString(); ingredients[i.Name] = i; } c.Ingredient = ingredients[iname]; r.Ingredients.Add(c); } foreach (var kv in JsonConvert.DeserializeObject <Dictionary <string, string> >(recipeJson[r_prop].ToString())) { var joinedkey = kv.Key + kv.Value; if (!properties.ContainsKey(joinedkey)) { properties[joinedkey] = new RecipeProperty { Type = kv.Key, Value = kv.Value } } ; r.Properties.Add(properties[joinedkey]); } recipeObjects.Add(r); successes++; } catch { failures++; } } Console.WriteLine($"ERROR: {failures}"); Console.WriteLine($"SUCCES: {successes}"); } try { Console.WriteLine("Attempting connection with database."); Console.WriteLine("Connection succeeded."); Console.WriteLine("Start Writing."); foreach (var recipe in recipeObjects) { _context.Recipes.Add(recipe); } _context.SaveChanges(); Console.WriteLine("Connection closed."); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } try { filename = @"C:\Users\Jasper De Vrient\Documents\Tin3\Project III\ApiBackEnd\EVARest\EVARest\restaurants.json"; const string rest_name = "name"; const string rest_lng = "lng"; const string rest_lat = "lat"; const string rest_website = "website"; const string rest_street = "street"; const string rest_postal = "postal"; const string rest_city = "city"; const string rest_phone = "phone"; const string rest_mail = "mail"; const string rest_body = "body"; using (StreamReader file = File.OpenText(filename)) using (JsonTextReader reader = new JsonTextReader(file)) { JArray restaurants = (JArray)JToken.ReadFrom(reader); foreach (var r in restaurants) { var restaurant = new Restaurant(); restaurant.Name = r[rest_name].ToString(); if (r[rest_lng] != null) { double outing; if (double.TryParse(r[rest_lng].ToString(), out outing)) { restaurant.Longitute = outing; } } if (r[rest_lat] != null) { double outing; if (double.TryParse(r[rest_lat].ToString(), out outing)) { restaurant.Latitude = outing; } } if (r[rest_postal] != null) { int outing; if (int.TryParse(r[rest_postal].ToString(), out outing)) { restaurant.Postal = outing; } } if (r[rest_body] != null) { restaurant.Description = r[rest_body].ToString(); } if (r[rest_city] != null) { restaurant.City = r[rest_city].ToString(); } if (r[rest_mail] != null) { restaurant.Email = r[rest_mail].ToString(); } if (r[rest_phone] != null) { restaurant.Phone = r[rest_phone].ToString(); } if (r[rest_street] != null) { restaurant.Street = r[rest_street].ToString(); } if (r[rest_website] != null) { restaurant.Website = r[rest_website].ToString(); } _context.Restaurants.Add(restaurant); } } _context.SaveChanges(); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } return(Ok()); }
public void AddRestaurant(Restaurant restaurant) { _db.Restaurants.Add(ToData(restaurant)); _db.SaveChanges(); Debug.Write("Added 1 Restaurant"); }