public List <PuppyDTO> getAllPuppies() { List <PuppyDTO> result = new List <PuppyDTO>(); IPuppy puppyRepo = new PuppyImpl(); List <Puppy> puppyList = puppyRepo.getAllPuppies(); for (int i = 0; i < puppyList.Count; i++) { Puppy onePuppy = puppyList[i]; PuppyDTO onePuppyDTO = new PuppyDTO() { Id = onePuppy.Id, Gender = onePuppy.Gender, Breed = onePuppy.Breed, Color = onePuppy.Color, OwnerName = onePuppy.OwnerName, Weight = onePuppy.Weight, DOB = onePuppy.DOB, DaysLived = getPuppyDaysSinceBirth(onePuppy), }; result.Add(onePuppyDTO); } return(result); }
public void UpdatePuppy(Puppy puppy) { try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand( @"Update puppy Set name = @name, weight = @weight, gender = @gender, paper_trained = @paper_trained Where id = @id", conn); cmd.Parameters.AddWithValue("@id", puppy.Id); cmd.Parameters.AddWithValue("@name", puppy.Name); cmd.Parameters.AddWithValue("@weight", puppy.Weight); cmd.Parameters.AddWithValue("@gender", puppy.Gender); cmd.Parameters.AddWithValue("@paper_trained", puppy.PaperTrained); cmd.ExecuteNonQuery(); } } catch (SqlException) { throw; } }
static void Main(string[] args) { Console.WriteLine("Exercise 1"); var dog = new Dog(); dog.Eat(); dog.Bark(); Console.WriteLine(); Console.WriteLine("Exercise 2"); var puppy = new Puppy(); puppy.Eat(); puppy.Bark(); puppy.Weep(); Console.WriteLine(); Console.WriteLine("Exercise 3"); dog.Eat(); dog.Bark(); var cat = new Cat(); cat.Eat(); cat.Meow(); }
static void Main() { Puppy puppy = new Puppy(); puppy.Eat(); puppy.Bark(); puppy.Weep(); }
static void Main() { Puppy pup = new Puppy(); pup.Eating(); pup.Bark(); pup.Weep(); }
public static void Main() { var puppy = new Puppy(); puppy.Eat(); puppy.Bark(); puppy.Weep(); }
static void Main(string[] args) { Puppy puppy = new Puppy(); puppy.Eat(); puppy.Bark(); puppy.Weep(); }
static void Main(string[] args) { var dog = new Puppy(); dog.Eat(); dog.Bark(); dog.Weep(); }
static void Main(string[] args) { Puppy sweety = new Puppy(); sweety.Weep(); sweety.Bark(); sweety.Eat(); }
static void Main(string[] args) { Puppy littleOne = new Puppy(); littleOne.Bark(); littleOne.Eat(); littleOne.Wheep(); }
static void Main(string[] args) { Dog dog = new Dog(); Puppy puppy = new Puppy(); dog.Bark(); puppy.Bark(); Console.ReadKey(); }
public IActionResult Work() { Puppy Pikachu = HttpContext.Session.GetObjectFromJson <Puppy>("Pikachu"); Pikachu.Work(); @ViewBag.Pikachu = HttpContext.Session.GetObjectFromJson <Puppy>("Pikachu"); HttpContext.Session.SetObjectAsJson("Pikachu", Pikachu); return(RedirectToAction("Index")); }
public IActionResult Post([FromBody] Puppy puppy) { if (puppy == null) { return(HttpBadRequest()); } Puppies.Add(puppy); return(CreatedAtRoute("GetPuppy", new { controller = "Puppy", id = puppy.Id }, puppy)); }
static void Main(string[] args) { Dog puppy = new Puppy("Beethoven"); Console.WriteLine(puppy.Voice()); Console.WriteLine(puppy.Bite()); Console.WriteLine(puppy.Jump()); Console.WriteLine(puppy.Run()); Console.ReadKey(); }
public static void PuppyPower() { Puppy theCutest = new Puppy(); Console.WriteLine(theCutest.Have()); Console.WriteLine(theCutest.HaveVocalChords()); Console.WriteLine(theCutest.Eat()); Console.WriteLine(theCutest.Chew()); Console.WriteLine(theCutest.Are()); }
private static void Main() { Animal animal = new Animal(); Dog dog = new Dog(); Puppy puppy = new Puppy(); animal.Eat(); dog.Bark(); puppy.Weep(); }
public static void Main(string[] args) { Puppy dog = new Puppy(); dog.Eat(); dog.Bark(); Cat cat = new Cat(); cat.Eat(); cat.Meow(); }
public static void Main(string[] args) { Console.WriteLine("*************************** Toy ***************************************"); var babyCube = new BabyCube(10, "VTech"); babyCube.Describe(); babyCube.SetLevel(1); Console.WriteLine("*************************** Birds ***************************************"); //Birds (the parent constructor was executed first before the child constructor) var goose = new Goose(true, 2, "seeds", "gray"); Console.WriteLine("*************************** Pets ***************************************"); //Pets(child can have its own methods Bark or Climb) var puppy = new Puppy(false, 4, "bones", "yellow"); puppy.Bark(); Console.WriteLine("---------------------------------"); var kitty = new Kitty(false, 4, "fish", "yellow"); kitty.Climb(); Console.WriteLine("*************************** Crawls ***************************************"); //Crawls(child can use its implemented interface methods and call the parent public methods) var turtle = new Turtle(false, 4, "insects", "brown"); turtle.Crawl(); turtle.Eat(); //turtle.Confidential(); turtle.MakePublic(); Console.WriteLine("---------------------------------"); var crocodile = new Crocodile(false, 4, "fish", "gray"); crocodile.Sleep(); crocodile.Crawl(); Console.WriteLine("---------------------------------"); var tortoise = new Tortoise(true, 4, "grass", "gray"); tortoise.Sleep(); tortoise.Crawl(); tortoise.Walk(); }
static void Main() { var dog = new Dog(); dog.Eat(); dog.Bark(); var puppy = new Puppy(); puppy.Eat(); puppy.Bark(); puppy.Weep(); }
public IActionResult GetPuppyById(int id) { Puppy puppy = puppyDao.GetPuppy(id); if (puppy == null) { return(NotFound()); } else { return(new JsonResult(puppy)); } }
public static void Main() { var puppy = new Puppy(); puppy.Eat(); puppy.Bark(); puppy.Weep(); var cat = new Cat(); cat.Eat(); cat.Meow(); }
public static void Main() { Dog dog = new Dog(); dog.Bark(); dog.Eat(); Puppy puppy = new Puppy(); puppy.Weep(); puppy.Bark(); puppy.Eat(); }
public IActionResult UpdatePuppy(Puppy puppy) { if (ModelState.IsValid) { // Updates puppy profile at id, returns 200 OK puppyDao.UpdatePuppy(puppy); return(Ok()); } else { // Sends errors to client program return(new BadRequestObjectResult(ModelState)); } }
static void Main(string[] args) { Animal animal = new Dog(); animal.Eat(); //we can access only eat (animal as Dog).Bark(); //we can access and bark Puppy animal2 = new Puppy(); animal2.Bark(); Cat animal3 = new Cat(); animal3.Meow(); }
static void Main() { Animal animal = new Animal(); Dog dog = new Dog(); Puppy puppy = new Puppy(); Cat cat = new Cat(); animal.Eat(); dog.Eat(); dog.Bark(); puppy.Eat(); puppy.Bark(); puppy.Weep(); cat.Eat(); cat.Meow(); }
public Puppy CreatePuppy(Puppy puppy) { var pup = new Puppy() { Id = puppy.Id, Name = puppy.Name, Breed = puppy.Breed, Age = puppy.Age, OwnerId = puppy.OwnerId, Owner = puppy.Owner, }; _context.Puppies.Add(pup); _context.SaveChanges(); return(pup); }
public Puppy UpdatePuppy(Puppy puppy) { var pup = _context.Puppies.Update(puppy); var owner = _context.Owners.FirstOrDefault(o => o.Id == puppy.OwnerId); _context.SaveChanges(); return(new Puppy() { Id = puppy.Id, Name = puppy.Name, Breed = puppy.Breed, Age = puppy.Age, OwnerId = puppy.OwnerId, Owner = owner, }); }
///<inheritdoc cref="IPuppyDao.GetPuppy(int)"/> /// <remarks> /// For simplicty sake ADO.net is used here. Alternate implementations could use EF, Dapper, or other micro-orms /// </remarks> public Puppy GetPuppy(int id) { try { Puppy rv = null; var connection = new SqlConnection(_connectionString); using (connection) { connection.Open(); var command = new SqlCommand(SqlScriptConstants.GET_PUPPY_SQL, connection); command.Parameters.Add(new SqlParameter("id", id)); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { var _pup = new Puppy // TODO: consider using the other Puppy constructor if you prefer. { Id = reader.GetInt32(0), // Referencing by position done for simplicity here. Name = reader.GetString(1), Weight = reader.IsDBNull(3) ? 0 : reader.GetInt32(2), // perhaps we don't know how much? Gender = reader.IsDBNull(3) ? null : reader.GetString(3), // perhaps we are not sure? PaperTrained = reader.IsDBNull(3) ? false : reader.GetBoolean(4) }; rv = _pup; } } reader.Close(); } #if DEBUG _logger.LogInformation("GetPuppy({0}) from SQL Server called", id); // TODO: Implement full logging solution when building production app #endif return(rv); } catch (SqlException ex) { _logger.LogError(ex, "GetPuppy SqlException ({0}) - {1}", id, ex.Message); throw; } catch (Exception ex) // TODO: Add basic catch-all library exception type instead of using System.Exception { _logger.LogError(ex, "GetPuppy ({0}) - {1}", id, ex.Message); throw; } }
static void Main(string[] args) { GermanShepherd shepherd = new GermanShepherd(); Corgi corgi = new Corgi(); Dog corgi1 = new Corgi(); Puppy puppy = new Puppy(); Console.WriteLine("Germanshepherd-Szczekanie:" + shepherd.Bark() + " Warczenie:" + shepherd.Growl()); Console.WriteLine("Typ Corgi:" + corgi.Bark()); Console.WriteLine("Inny typ:" + corgi1.Bark()); Console.WriteLine("Szczeniak:" + "Warczenie:" + puppy.Growl() + " Szczekanie:" + puppy.Bark()); Console.ReadKey(); }
public IActionResult Put(int id, [FromBody] Puppy puppy) { Puppy oldPup = Puppies.Find(id); if (oldPup != null) { int oldId = oldPup.Id; puppy.Id = oldId; Puppies.Remove(oldId); Puppies.Update(puppy); return(new NoContentResult()); } else { return(HttpBadRequest()); } }
static void Main(string[] args) { Animal animal; Console.WriteLine("Would you raise a tiger or a puppy?"); Console.WriteLine("1 = tiger, 2 = puppy"); int choice2; again: try { choice2 = int.Parse(Console.ReadLine()); } catch (Exception) { goto again; } switch (choice2) { case 1: animal = new Tiger(); break; case 2: animal = new Puppy(); break; default: goto again; } int choice = 0; while (animal.isAlive()) { try_again: Console.WriteLine("Animal status age "+ animal.Age+" fullness "+ animal.Fullness+" happiness "+ animal.Happiness); Console.WriteLine("1 Drink"); Console.WriteLine("2 Eat"); Console.WriteLine("3 Pee"); Console.WriteLine("4 Stay"); Console.WriteLine("5 Sit"); Console.WriteLine("6 Pet"); Console.WriteLine("7 MakeSound"); Console.WriteLine("8 Mood"); try { choice = int.Parse(Console.ReadLine()); } catch (Exception) { goto try_again; } switch (choice) { case 1: animal.Drink(); break; case 2: animal.Eat(); break; case 3: animal.Pee(); break; case 4: animal.Stay(); break; case 5: animal.Sit(); break; case 6: animal.Pet(); break; case 7: animal.MakeSound(); break; case 8: Console.WriteLine(animal.Mood()); break; } goto try_again; } }