public ActionResult Create(Dinner dinner) { if (ModelState.IsValid) { try { // TODO: Add insert logic here //var db = new DB(); //db.Dinners.InsertOnSubmit(dinner); _repository.Add(dinner); //try //{ // _repository.SubmitChanges(); //} //catch (Exception e) //{ // Console.WriteLine("{0} Exception caught.", e); //} return RedirectToAction("Index"); } catch { return View(dinner); } } else { return View(dinner); } }
public FakeDinnerRepository() { dinners = new List<Dinner>(); for (int i = 0; i < 100; i++) { var dinner = new Dinner(); dinner.Title = "dinner" + i; dinner.Longitude = -100.00; dinner.Latitude = 35.00; dinner.HostedBy = "Test"; dinner.EventTime = "After Work"; dinner.EventDate = DateTime.Now.AddDays(1); if (i >= 50) { dinner.EventDate = DateTime.Now.AddDays(-1); } dinner.Description = "Test Dinner"; dinner.Address = "Address " + i; dinner.ContactPhone = "555-5555"; dinners.Add(dinner); } }
private string DinnerHostPartner(Dinner dinner, Guid userId) { if (dinner.Partner == null) return null; return dinner.Partner.Id == userId ? dinner.User.FullName() : dinner.Partner.FullName(); }
Dinner ReverseDinner(Dinner yum) { if(yum == Dinner.Turkey) yum = Dinner.Potatoes; else if(yum == Dinner.Potatoes) yum = Dinner.Turkey; return yum; }
private static object MapToGridModel(Dinner o) { return new { o.Id, o.Name, o.Date, ChefName = o.Chef.FirstName + " " + o.Chef.LastName, Meals = string.Join(", ", o.Meals.Select(m => m.Name)) }; }
public void Dinner_Should_Not_Be_Valid_When_Some_Properties_Incorrect() { //Arrange Dinner dinner = new Dinner() { Title = "Test title", Country = "USA", ContactPhone = "BOGUS" }; // Act bool isValid = dinner.IsValid; //Assert Assert.IsFalse(isValid); }
public ActionResult Register(int id) { Dinner dinner = dinnerRepository.Find(id); if (!dinner.IsUserRegistered(User.Identity.Name)) { RSVP rsvp = new RSVP(); NerdIdentity nerd = (NerdIdentity)User.Identity; rsvp.AttendeeNameId = nerd.Name; rsvp.AttendeeName = nerd.FriendlyName; dinner.RSVPs.Add(rsvp); dinnerRepository.Save(); } return(Content(Resources.Resources.ThanksSeeYouThere)); }
public void IsValid_GivenProductWithMealsAndDrinks_ExpectTrue() { var meals = new List <Product>() { new Product("meal 1", 0.00F, ProductType.Meal), new Product("meal 2", 0.00F, ProductType.Meal) }; var drinks = new List <Product>() { new Product("drink 1", 0.00F, ProductType.Drink), new Product("drink 2", 0.00F, ProductType.Drink), new Product("drink 3", 0.00F, ProductType.Drink) }; Dinner dinner = new Dinner(meals, drinks); Assert.True(dinner.IsValid()); }
public ActionResult Edit(int id) { Dinner dinner = dinnerRepository.GetDinner(id); //ViewData["Countries"] = new SelectList(PhoneValidator.Countries, dinner.Country); //return View(dinner); if (!dinner.IsHostedBy(User.Identity.Name)) { return(View("InvalidOwner")); } else { return(View(new DinnerFormViewModel(dinner))); } }
public Dinner CreateDinner(Dinner dinner) { var rsvp = new Rsvp { UserName = dinner.UserName }; dinner.Rsvps = new List <Rsvp> { rsvp }; _context.Add(dinner); _context.Add(rsvp); _context.SaveChanges(); return(dinner); }
private JsonDinner JsonDinnerFromDinner(Dinner dinner) { return(new JsonDinner { DinnerID = dinner.DinnerID, EventDate = dinner.EventDate, Latitude = dinner.Latitude, Longitude = dinner.Longitude, Title = dinner.Title, Description = dinner.Description, RSVPCount = dinner.RSVPs.Count, //TODO: Need to mock this out for testing... //Url = Url.RouteUrl("PrettyDetails", new { Id = dinner.DinnerID } ) Url = dinner.DinnerID.ToString() }); }
public ActionResult Register(int id) { Dinner dinner = dinnerRepository.Find(id); if (!dinner.IsUserRegistered(User.Identity.Name)) { RSVP rsvp = new RSVP(); NerdIdentity nerd = (NerdIdentity)User.Identity; rsvp.AttendeeNameId = nerd.Name; rsvp.AttendeeName = nerd.FriendlyName; dinner.RSVPs.Add(rsvp); dinnerRepository.SubmitChanges(); } return(Content("Thanks - we'll see you there!")); }
public ActionResult Create(Dinner dinner) { if (ModelState.IsValid) { dinner.HostedBy = User.Identity.Name; var eventMessage = new DinnerCreatedEvent { Dinner = Mapper.Map <entities.Dinner>(dinner), CreatedAt = DateTime.UtcNow }; MessageQueue.Publish(eventMessage); return(RedirectToAction("Index")); } return(View(dinner)); }
public ActionResult Create() { var countries = new List <string>(); countries.Add("America"); countries.Add("Australia"); countries.Add("Austria"); ViewData["Countries"] = new SelectList(countries); Dinner dinner = new Dinner() { EventDate = DateTime.Now.AddDays(7) }; return(View(new DinnerFormViewModel(dinner))); }
public virtual async Task <Dinner> CreateDinnerAsync(Dinner dinner) { var rsvp = new Rsvp { UserName = dinner.UserName }; dinner.Rsvps = new List <Rsvp> { rsvp }; _database.Add(dinner); _database.Add(rsvp); await _database.SaveChangesAsync(); return(dinner); }
public ActionResult Edit(int id, FormCollection formValues) { // Retrieve existing dinner Dinner dinner = dinnerRepository.GetDinner(id); if (!dinner.IsHostedBy(User.Identity.Name)) { return(View("InvalidOwner")); } UpdateModel(dinner); // Persist changes back to database dinnerRepository.Save(); // Perform HTTP redirect to details page for the saved Dinner return(RedirectToAction("Details", new { id = dinner.DinnerId })); }
public ActionResult Delete(int id) { Dinner dinner = dinnerRepository.GetDinner(id); if (dinner == null) { return(View("NotFound")); } if (!dinner.IsHostedBy(User.Identity.Name)) { return(View("InvalidOwner")); } return(View(dinner)); }
public ActionResult Create(Dinner dinner) { if (ModelState.IsValid) { dinner.HostedBy = User.Identity.Name; Rsvp rsvp = new Rsvp(); rsvp.AttendeeName = User.Identity.Name; dinner.Rsvps.Add(rsvp); dinnerRepository.Add(dinner); dinnerRepository.Save(); return(RedirectToAction("Index")); } return(View(new DinnerFormViewModel(dinner))); }
public ActionResult Edit(int id, FormCollection formValues) { Dinner dinner = iDinnerRepos.GetDinner(id); if (!dinner.IsHostedBy(User.Identity.Name)) { return(View("InvalidOwner")); } try { //dinner.Title = Request.Form["Title"]; //dinner.Description = Request.Form["Description"]; //dinner.EventDate = DateTime.Parse(Request.Form["EventDate"]); //dinner.Address = Request.Form["Address"]; ////dinner.Country = new Country(Request.Form["CountryID"]); //dinner.Country = iDinnerRepos.GetCountry(Convert.ToInt32(Request.Form["CountryID"])); ////dinner.Country = Request.Form["Country"]; //dinner.ContactEmail = Request.Form["ContactEmail"]; UpdateModel(dinner); iDinnerRepos.Save(); ViewBag.CountryID = new SelectList(iDinnerRepos.GetCountries(), "CountryID", "Name", dinner.CountryID); return(RedirectToAction("Details", new { id = dinner.DinnerID })); } catch { return(View(new DinnerFromViewModel(dinner))); } //if (ModelState.IsValid) //{ // dinner.DinnerID = id; // if (!dinner.IsHostedBy(User.Identity.Name)) // { // return View("InvalidOwner"); // } // //nerdDinnersDB.Entry(dinner).State = EntityState.Modified; // nerdDinnersDB.SaveChanges(); // return RedirectToAction("Details", new {id = dinner.DinnerID}); //} //ViewBag.CountryID = new SelectList(nerdDinnersDB.Countries, "CountryID", "Name", dinner.CountryID); //return View(new DinnerFromViewModel(dinner)); ////return View(dinner); }
public void Construct_CreatedWithMealsAndDrinksAsList_ExpectDinnerWithMealsAndDrinks() { var meals = new List <Product>() { new Product("meal 1", 0.00F, ProductType.Meal), new Product("meal 2", 0.00F, ProductType.Meal) }; var drinks = new List <Product>() { new Product("drink 1", 0.00F, ProductType.Drink), new Product("drink 2", 0.00F, ProductType.Drink), new Product("drink 3", 0.00F, ProductType.Drink) }; Dinner dinner = new Dinner(meals, drinks); Assert.Equal(drinks, dinner.Drinks); Assert.Equal(meals, dinner.Meals); }
public ActionResult My() { _nerdIdentity = this.nerdIdentity; // TODO Infi Coding Dojo: optimize this var userDinners = from dinner in Dinner.HydrateAll(dinnerRepository.All.ToList(), dinnerRepository.AllEvents.ToList()) where ( String.Equals((dinner.HostedById ?? dinner.HostedBy), _nerdIdentity.Name) || dinner.RSVPs.Any(r => r.AttendeeNameId == _nerdIdentity.Name || (r.AttendeeNameId == null && r.AttendeeName == _nerdIdentity.Name)) ) orderby dinner.EventDate select dinner; return(View(userDinners)); }
public async Task <IActionResult> CreateDinnerAsync([FromBody] Dinner dinner) { if (ModelState.IsValid) { //var user = await _userManager.FindByIdAsync(Context.User.GetUserId()); dinner.UserName = User.Identity.Name; GeoLocation.SearchByPlaceNameOrZip(dinner); dinner = await _repository.CreateDinnerAsync(dinner); var url = Url.RouteUrlAbsolute("GetDinnerById", new { id = dinner.DinnerId }); HttpContext.Response.StatusCode = (int)HttpStatusCode.Created; HttpContext.Response.Headers["Location"] = url; return(new ObjectResult(dinner)); } return(BadRequest()); }
private ViewResult DeleteGet(int id) { Dinner dinner = _dinnerRepository.GetDinner(id); if (dinner == null) { return(View(ViewNames.NotFound)); } ViewResult viewResult = ModificationNotAuthorized(dinner); if (viewResult != null) { return(viewResult); } return(View(dinner.ToViewModel())); }
public ActionResult Register(int id) { Dinner dinner = nerdDinnerDB.Dinners.Find(id); if (!dinner.IsUserRegistered(User.Identity.Name)) { RSVP rsvp = new RSVP(); rsvp.AttendeeName = User.Identity.Name; //if (dinner.RSVPs == null) //{ // dinner.RSVPs = new List<RSVP>(); //} dinner.RSVPs.Add(rsvp); nerdDinnerDB.SaveChanges(); } return(Content("Thanks - we'll see you there!")); }
public ContentResult Rsvp(int dinnerID) { Dinner dinner = _dinnerRepository.GetDinner(dinnerID); string userName = User.Identity.Name; if (!dinner.UserHasRsvp(userName)) { var rsvp = new RSVP { AttendeeName = userName }; dinner.RSVPs.Add(rsvp); _dinnerRepository.Save(); } return(Content(Messages.RsvpConfirmation)); }
public async Task <Dinner> AddDinner(string dinner, string createdBy) { using (var db = new ZombieRunnerDbContex()) { var data = new Dinner { Seed = new Random().Next(DateTime.UtcNow.Millisecond * 1000), Content = dinner, IsEnabled = true, CreatedOn = DateTime.UtcNow, CreatedBy = createdBy, ModifiedOn = DateTime.UtcNow }; db.Entry(data).State = EntityState.Added; await db.SaveChangesAsync(); return(data); } }
public ActionResult Create(Dinner dinner) { if (ModelState.IsValid) { dinner.HostedBy = User.Identity.Name; dinner.DinnerID = dinnerRepository.GetUnusedDinnerID(); dinnerRepository.Add(dinner); dinnerRepository.Save(); return(RedirectToAction("Details", new { id = dinner.DinnerID })); } Dinner newDinner = new Dinner() { EventDate = DateTime.Now.AddDays(7) }; return(View(new DinnerFormViewModel(newDinner))); }
public async Task <IActionResult> UpdateDinnerAsync(int id, [FromBody] Dinner dinner) { if (dinner.DinnerId != id) { return(View("Error")); } var user = HttpContext.User; if (!dinner.IsUserHost(user.Identity.Name)) { return(View("Error")); } GeoLocation.SearchByPlaceNameOrZip(dinner); dinner = await _repository.UpdateDinnerAsync(dinner); return(new ObjectResult(dinner)); }
public void Dinner_Should_Be_Valid_When_All_Properties_Correct() { Dinner dinner = new Dinner() { Title = "Test Title", Description = "Some description", EventDate = DateTime.Now, HostedBy = "Blah", Address = "One Microsoft Way", Country = countires.Single(c => c.Name == "USA"), ContactEmail = "*****@*****.**", Latitude = 93, Longitude = -92 }; //bool isValid = dinner.IsValid; //Assert.IsTrue(isValid); }
public async Task Get_DocumentExists_DinnerObjectReturned() { // Arrange var familyId = Guid.NewGuid(); var date = new LocalDate(2021, 1, 1); var dinner = Dinner.CreateNew(familyId, date); await _dinnerRepository.SaveAsync(dinner); try { // Act var result = await _dinnerRepository.GetAsync(familyId, date); Assert.Equal(result.Id, dinner.Id); } finally { await _dinnerRepository.DeleteAsync(dinner); } }
public ActionResult Create(Dinner dinner) { if (ModelState.IsValid) { dinner.HostedBy = User.Identity.Name; RSVP rsvp = new RSVP(); rsvp.AttendeeName = User.Identity.Name; dinner.RSVPs = new List <RSVP>(); dinner.RSVPs.Add(rsvp); db.Dinners.Add(dinner); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dinner)); }
// // GET: /Dinners/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new FileNotFoundResult { Message = Resources.Resources.NoDinnerFoundInvalidId }); } Dinner dinner = dinnerRepository.Find(id.Value); if (dinner == null) { return(new FileNotFoundResult { Message = Resources.Resources.NoDinnerFoundForId }); } return(View(dinner)); }
public ActionResult Create(Dinner dinner) { if (ModelState.IsValid) { try { dinner.HostedBy = "SomeUser"; dinnerRepository.Add(dinner); dinnerRepository.Save(); return(RedirectToAction("Details", new{ id = dinner.DinnerID })); } catch { ModelState.AddRuleViolations(dinner.GetRuleViolations()); } } return(View(dinner)); }
public ActionResult Delete(int id, string confirmButton) { Dinner dinner = dinnerRepository.Find(id); if (dinner == null) { return(View("NotFound")); } if (!dinner.IsHostedBy(User.Identity.Name)) { return(View("InvalidOwner")); } dinnerRepository.Delete(id); dinnerRepository.Save(); return(View("Deleted")); }
public async Task <ActionResult> Create(Dinner dinner) { if (dinner != null) { var dinners = await _repository.Search(dinner.Date); if (dinners == null) { await _repository.Add(_mapper.Map <DinnerDao>(dinner)); } else { // Failed to add dinner. return(View("AddDinner", new Dinner())); } } return(RedirectToAction("Index")); }
public async Task <IActionResult> UpdateDinnerAsync(int id, [FromBody] Dinner dinner) { if (dinner.DinnerId != id) { return(new HttpStatusCodeResult((int)HttpStatusCode.BadRequest)); } var user = await _userManager.FindByIdAsync(Context.User.GetUserId()); if (!dinner.IsUserHost(user.UserName)) { return(HttpNotFound()); } GeoLocation.SearchByPlaceNameOrZip(dinner); dinner = await _repository.UpdateDinnerAsync(dinner); return(new ObjectResult(dinner)); }
public void Dinner_Should_Be_Valid_When_All_Properties_Correct() { //Arrange Dinner dinner = new Dinner { Title = "Test title", Description = "Some description", EventDate = DateTime.Now, HostedBy = "ScottGu", Address = "One Microsoft Way", Country = "USA", ContactPhone = "425-703-8072", Latitude = 93, Longitude = -92, }; // Act bool isValid = dinner.IsValid; //Assert Assert.IsTrue(isValid); }
public MainViewModel(DishWindow dishWindow, IngredientsWindow ingredientsWindow, PreparationWindow preparationWindow) { _dinner = new Dinner(); _dishWindow = dishWindow; _ingredientsWindow = ingredientsWindow; _preparationWindow = preparationWindow; _dishViewModel = (DishViewModel) _dishWindow.DataContext; _ingredientsViewModel = (IngredientsViewModel) _ingredientsWindow.DataContext; _preparationViewModel = (PreparationViewModel) _preparationWindow.DataContext; Starters = new ObservableCollection<Dish>(); Mains = new ObservableCollection<Dish>(); Desserts = new ObservableCollection<Dish>(); Menu = new ObservableCollection<Dish>(); _hideErrorTextTimer = new System.Timers.Timer(ErrorTextDisplayTime) {AutoReset = false}; _hideErrorTextTimer.Elapsed += (sender, args) => Application.Current.Dispatcher.Invoke(() => ErrorTextVisible = false); ShowPreparations = new DelegateCommand(o => { _preparationViewModel.Starter = _dinner.GetSelectedDish(DishType.Starter); _preparationViewModel.Main = _dinner.GetSelectedDish(DishType.Main); _preparationViewModel.Dessert = _dinner.GetSelectedDish(DishType.Dessert); _preparationWindow.Show(); }, o => Menu.Any()); ShowIngredients = new DelegateCommand(o => { _ingredientsViewModel.Ingredients = _dinner.AllIngredients; _ingredientsWindow.Show(); }, o => Menu.Any()); _dinner.MenuChanged += OnMenuChanged; _dinner.FilteredDishes += DinnerOnFilteredDishes; _dinner.ErrorGettingFilteredDishes += DinnerOnErrorGettingFilteredDishes; _dinner.DishesChanged += OnDishesChanged; _dinner.NumberOfGuestsChanged += OnNumberOfGuestsChanged; }
public void Delete(Dinner dinner) { var listDinner = GetDinner(dinner.DinnerId); dinners.Remove(listDinner); }
public void Add(Dinner dinner) { db.Dinners.InsertOnSubmit(dinner); db.SubmitChanges(); }
public void Delete(Dinner dinner) { db.Dinners.DeleteOnSubmit(dinner); db.SubmitChanges(); }
public void Update(Dinner dinner) { var listDinner = GetDinner(dinner.DinnerId); Delete(listDinner); Add(dinner); }
public void Add(Dinner dinner) { dinners.Add(dinner); }
public void Update(Dinner dinner) { db.SubmitChanges(); }