public void updateKennelAvailability(DateTime date, string id, Kennel kennel) { //for the date the loop is on in the iteration it will check to see if the date already exists bool dateExists = db.KennelAvailability.Where(k => k.KennelID.ToUpper() == id.ToUpper() && k.BookingDate == date).Count() > 0; //if the date does not exist it will add it to the table if (dateExists == false) { var newDate = new KennelAvailability() { KennelID = id.ToUpper(), BookingDate = date, Availability = 1 }; db.KennelAvailability.Add(newDate); } //if the date does exists it will update the existing entry. else { //Adds 1 to Availability on the KennelAvailability table where the KennelId and Date match those of the booking. var ka = db.KennelAvailability.Where(r => r.KennelID.ToUpper() == id.ToUpper() && r.BookingDate == date).First(); ka.Availability += 1; db.Entry(ka).State = EntityState.Modified; //Updates the KennelAvailability to full if the kennel has reached capacity for that date. if (ka.Availability == kennel.Capacity) { ka.Full = true; db.Entry(ka).State = EntityState.Modified; } } }
public ActionResult DeleteConfirmed(int id) { Kennel kennel = db.Kennels.Find(id); db.Kennels.Remove(kennel); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> DeleteConfirmed(string id) { Kennel kennels = await db.Kennel.FindAsync(id); db.Kennel.Remove(kennels); await db.SaveChangesAsync(); return(RedirectToAction("MyKennels")); }
public ActionResult Edit([Bind(Include = "Kennel_ID,Kennel_Name,Kennel_Number,Kennel_Capacity")] Kennel kennel) { if (ModelState.IsValid) { db.Entry(kennel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(kennel)); }
public ActionResult Create([Bind(Include = "Kennel_ID,Kennel_Name,Kennel_Number,Kennel_Capacity")] Kennel kennel) { if (ModelState.IsValid) { db.Kennels.Add(kennel); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(kennel)); }
// GET: Kennels/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Kennel kennel = db.Kennels.Find(id); if (kennel == null) { return(HttpNotFound()); } return(View(kennel)); }
public async Task <ActionResult> Edit([Bind(Include = "KennelID,Name,Address,County,Town,PhoneNumber,Email,Capacity,PricePerNight,PricePerWeek,MaxDays,LgeDog,MedDog,SmlDog,CancellationPeriod,Description,Grooming,Training")] Kennel kennels) { if (ModelState.IsValid) { //Capitalises to title case when updated kennels.Name = TitleCase(kennels.Name); kennels.Address = TitleCase(kennels.Address); kennels.Town = TitleCase(kennels.Town); //Updates the database entry db.Entry(kennels).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("MyKennels")); } return(View(kennels)); }
public bool CreateKennel(KennelCreate kennelCreate) { Kennel kennel = new Kennel { KennelNumber = kennelCreate.KennelNumber, Size = kennelCreate.Size, Occupied = kennelCreate.Occupied, DoggoID = kennelCreate.DoggoID, DoggoName = kennelCreate.DoggoName, FullName = kennelCreate.FullName, }; using (var ctx = new ApplicationDbContext()) { ctx.Kennels.Add(kennel); return(ctx.SaveChanges() == 1); } }
// GET: Kennels/Delete/{KennelID} public async Task <ActionResult> Delete(string id) { var currentUser = GetUser(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Kennel kennels = await db.Kennel.FindAsync(id); if (kennels == null) { return(HttpNotFound()); } //Only the kennel owner is authorized to delete the kennel if (kennels.User != currentUser) { TempData["Unauth"] = "You are not authorised to do that, log in as a different user"; return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized)); } return(View(kennels)); }
public async Task <ActionResult> Create([Bind(Include = "KennelID,Name,Address,County,Town,PhoneNumber,Email,Capacity,PricePerNight,PricePerWeek,MaxDays,LgeDog,MedDog,SmlDog,CancellationPeriod,Description,Grooming,Training")] Kennel kennels) { var currentUser = GetUser(); if (ModelState.IsValid) { kennels.User = currentUser; //Capitalises in title case when added to the database kennels.KennelID = kennels.KennelID.ToUpper(); kennels.Name = TitleCase(kennels.Name); kennels.Address = TitleCase(kennels.Address); kennels.Town = TitleCase(kennels.Town); //Adds the kennel to the database db.Kennel.Add(kennels); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(kennels)); }
// GET: Kennels/Details/{KennelID} public async Task <ActionResult> Details(string id) { Booking sd = TempData["searchDates"] as Booking; TempData["searchDates"] = sd; IsKennelOwner(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Kennel kennels = await db.Kennel.FindAsync(id); if (kennels == null) { return(HttpNotFound()); } getAvRate(id); return(View(kennels)); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); Console.WriteLine("Welcome to OO"); // Four pillars of OO: // Inheritance. var book = new Book(); var paper = new Paper(); book.Publish(); book.ReadBook(); paper.Publish(); // Encapsulation. var test = new Test(); test.Description = "Something!"; Console.WriteLine(test.Description); // Polymorphism. Publication bookTwo = new Book(); //bookTwo.ReadBook(); // method from book if (bookTwo is Book) { ((Book)bookTwo).ReadBook(); } bookTwo.Publish(); // method from publication bookTwo.ToString(); // method from object IList <Publication> publications = new List <Publication>(); publications.Add(new Book()); publications.Add(new Book()); publications.Add(new Paper()); publications.Add(new Paper()); publications.Add(new Comic()); publications.Add(new Comic()); foreach (var currentPublication in publications) { currentPublication.CleanPublication(); if (currentPublication is Comic) { ((Comic)currentPublication).PutInZiplock(); } } // Abstraction. IDataConnection connection; bool isTest = true; if (isTest) { connection = new DummyFileConnection(); } else { connection = new DatabaseConnection(); } // code code code connection.GetData(); // code code code connection.PushData(); //var publication = new Publication(); not possible cause abstract. // Other topics. // DateTime. var date = DateTime.Now; Console.WriteLine(date); // Stringbuilder / String.Format string wat = "fdsgdfg"; wat = "sddsfdaaf"; wat = wat + "1df"; var builder = new StringBuilder("Hello World!", 25); builder.Append("wat"); var niceString = string.Format("There is a {0} at {1}", "Dog", "The Farm"); Console.WriteLine(niceString); // Structs var coords = new Coordinate(10, 20); Console.WriteLine(coords); // User input. //Console.Write("Select Country (USA or BEL): "); //string country = Console.ReadLine(); // Dictionary. var dictionary = new Dictionary <int, string>(); dictionary.Add(1, "One"); dictionary.Add(5, "Five"); foreach (var kvp in dictionary) { Console.WriteLine(string.Format("For key: {0} there is the value: {1}", kvp.Key, kvp.Value)); } string country = "USA"; // user input var countries = new Dictionary <string, string>(); countries.Add("USA", "Star Spangled Banner"); countries.Add("BEL", "Yellow-Red-Black"); Console.WriteLine(countries[country]); // Exceptions var kennel = new Kennel(); var success = kennel.WalkBy(); if (!success) { Console.WriteLine("Could not walk by the kennel!"); } var dog = new Dog(); try { dog.DoRoll(); } catch (IndexOutOfRangeException ex) { } catch (Exception e) { Console.WriteLine("Roll Exception!"); } // var connection = new DBConnection(); try { dog.ChewOnBone(); dog.ChewOnBone(); // connection.Connect(); // var result = connection.Execute("SELECT * FROM"); } catch (NoBonesException ex) { Console.WriteLine("The dog is out of bones..."); } finally { // connection.Close(); Console.WriteLine("This happens regardless of exc or not"); } // Events var counter = new Counter(); counter.GoalReached += CounterGoalReached; counter.GoalReached += CounterGoalReachedAgain; for (int i = 0; i < 20; i++) { Console.WriteLine("Adding one to the counter"); counter.Add(1); } // Types of .Net Core Projects. // .NET Core Console // ASP.NET Core // MVC (actually uses razor for the frontend) <-- Focus // Razorpages (razor html - class) // Blazor // ASP.NET API // ASP.NET API - Angular Frontend / React Frontend // Xamarin (Mobile) // Windows Clients Apps (Windows Forms, WPF, UWP, GTK) // IoT / Machine Learning (GPIO, ML.NET) }
//private static double Momspct = 0.25; static void Main(string[] args) { // så kan man spørge på argumenter til programmet if (args.Length > 0) { foreach (var item in args) { System.Console.WriteLine(item); } ; } ; // Så kan man hente i konfigurationsfilen //modul+add+reference: system.coonfiguration string m = System.Configuration.ConfigurationManager.AppSettings["moms"]; double moms = 0; if (m != null) { moms = Convert.ToDouble(m); } //Eller bruge program properties + settings. //kan bruges som en mini dattabase. string x = Module11_Collections.Properties.Settings.Default.Xpos; System.Collections.ArrayList lst1 = new System.Collections.ArrayList(); lst1.Add(1); lst1.Add(2); lst1.Remove(1); System.Collections.ArrayList lst2 = new System.Collections.ArrayList(); lst2.Add(new Hund() { Navn = "a" }); lst2.Add(new Hund() { Navn = "b" }); lst2.Remove(1); System.Collections.Stack lst3 = new System.Collections.Stack(); lst3.Push(1); lst3.Push(2); lst3.Push(133); System.Collections.Queue lst4 = new System.Collections.Queue(); lst4.Enqueue(new Hund() { Navn = "A" }); lst4.Enqueue(new Hund() { Navn = "B" }); lst4.Enqueue(new Hund() { Navn = "C" }); Hund h = (Hund)lst4.Dequeue(); System.Collections.Hashtable lst5 = new System.Collections.Hashtable(); lst5.Add("a", "a"); lst5.Add("b", "a"); lst5.Add("c", "a"); string r = lst5["b"].ToString(); Kennel kennel = new Kennel(); kennel.TilføjHund(h); ////////////////// System.Collections.Generic.List <Hund> lst6 = new System.Collections.Generic.List <Hund>(); lst6.Add(new Hund() { Navn = "a" }); lst6.Add(new Hund() { Navn = "b" }); Hund hh = lst6[0]; Queue <int> lst7 = new Queue <int>(); lst7.Enqueue(5); int ii = lst7.Dequeue(); Dictionary <int, Hund> lst8 = new Dictionary <int, Hund>(); lst8.Add(4, new Hund() { Navn = "b" }); lst8.Add(22, new Hund() { Navn = "g" }); Hund hhh = lst8[4]; List <string> lst9 = new List <string>(); lst9.Add("A1"); lst9.Add("B1"); lst9.Add("E1"); lst9.Add("C1"); foreach (var item in lst9) { System.Console.WriteLine(item); } for (int i = 0; i < lst9.Count; i++) { System.Console.WriteLine(lst9[i].ToString()); } //Test<MinType> t1 = new Test<MinType>(); Kennel2 k2 = new Kennel2(); //k2.Add(new Hund); //k2.Add(Hund ); if (System.Diagnostics.Debugger.IsAttached) { System.Console.Write("Press any key to continue . . . "); System.Console.ReadKey(); } }
public async Task DeleteKennelAsync(Kennel KennelToDelete) { applicationContext.Kennels.Remove(KennelToDelete); await applicationContext.SaveChangesAsync(); }