Ejemplo n.º 1
0
        //Read, Details of a specific dog
        public DogClass ReadOne(int?id)
        {
            DogClass d = new DogClass();

            using (SqlConnection sqlconn = new SqlConnection(mainconn))
            {
                SqlCommand sqlcomm = new SqlCommand("SP_ReadDog", sqlconn);
                sqlcomm.CommandType = CommandType.StoredProcedure;

                //pass in the dogclass model properties
                sqlcomm.Parameters.AddWithValue("@DogID", id);

                //open db connection
                sqlconn.Open();
                SqlDataReader rdr = sqlcomm.ExecuteReader();
                //Excute or invoke the CreateDog stored procedure
                //use while loop

                while (rdr.Read())
                {
                    d.ID      = Convert.ToInt32(rdr["DogId"]);
                    d.Name    = rdr["DogName"].ToString();
                    d.Breed   = rdr["Breed"].ToString();
                    d.Gender  = rdr["Gender"].ToString();
                    d.Comment = rdr["Comment"].ToString();
                }
                //Close db connection
                sqlconn.Close();
            }
            return(d);
        }
Ejemplo n.º 2
0
        public List <DogInfoDTO> getByUserId(int userId)
        {
            List <Dog> dogs = context.Dog.Where(d => d.OwnerId == userId).ToList();

            if (dogs.Count < 1)
            {
                throw new AppException("Nie odnaleziono psów");
            }
            List <DogInfoDTO> dogInfo = new List <DogInfoDTO>();

            foreach (Dog dog in dogs)
            {
                DogBreed breed    = context.DogBreed.Where(db => db.BreedId == dog.BreedId).FirstOrDefault();
                DogClass dogClass = context.DogClass.Where(dc => dc.ClassId == dog.ClassId).FirstOrDefault();

                dogInfo.Add(new DogInfoDTO
                {
                    dogId      = dog.DogId,
                    name       = dog.Name,
                    breedName  = breed.NamePolish,
                    className  = dogClass.NamePolish,
                    chipNumber = dog.ChipNumber
                });
            }
            return(dogInfo);
        }
Ejemplo n.º 3
0
        //List
        public List <DogClass> ListDogs()
        {
            List <DogClass> Ldog = new List <DogClass>();

            using (SqlConnection sqlconn = new SqlConnection(mainconn))
            {
                SqlCommand sqlcomm = new SqlCommand("ListDog", sqlconn);
                sqlcomm.CommandType = CommandType.StoredProcedure;

                //open db connection
                sqlconn.Open();
                SqlDataReader rdr = sqlcomm.ExecuteReader();
                //Excute or invoke the CreateDog stored procedure
                //use while loop

                while (rdr.Read())
                {
                    DogClass d = new DogClass();
                    d.ID      = Convert.ToInt32(rdr["DogId"]);
                    d.Name    = rdr["DogName"].ToString();
                    d.Breed   = rdr["Breed"].ToString();
                    d.Gender  = rdr["Gender"].ToString();
                    d.Comment = rdr["Comment"].ToString();
                    //populate the Ldog List
                    Ldog.Add(d);
                }

                //Close db connection
                sqlconn.Close();
            }
            return(Ldog);
        }
    // Use this for initialization
    void Start()
    {
        IDogClass MynewDog = new LabradorRetriever();

        print(" My Dog Color is " + MynewDog.Color);
        print("My Dogs Aging rate is " + MynewDog.CurrentAging() + "%");


        DogClass  BullDog    = new DogClass(3, 10, "BullDog", "White", 15);
        IDogClass JohnNewDog = new DogClass(5, 10, "Lab", "Brown", 11);
    }
Ejemplo n.º 5
0
 public ActionResult Edit(DogClass dog)
 {
     if (ModelState.IsValid)
     {
         //update db
         db.UpdateDog(dog);
         return(RedirectToAction("Index"));
     }
     //if the model state is not valid
     return(View(dog));
 }
Ejemplo n.º 6
0
        public ActionResult Create(DogClass dog)
        {
            if (ModelState.IsValid)
            { //Insert the form info to db
                db.CreateDog(dog);

                return(RedirectToAction("Index"));
            }

            //if the model state is not valid
            return(View(dog));
        }
Ejemplo n.º 7
0
        // GET:Workers/Edit/4
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //check if the worker exist in db
            DogClass dog = db.ReadOne(id);

            if (dog == null)
            {
                return(HttpNotFound());
            }
            return(View(dog));
        }
Ejemplo n.º 8
0
    void Start()
    {       // i. Write a function that uses a condition:
            //Testing and Printing:
        if (CheckPrime(someNumber))
        {
            print("The number " + someNumber + " is a prime number");
        }
        else
        {
            print("The number " + someNumber + " is not a prime number");
        }

        DogClass Jimmy = new DogClass("Jimmy", "Old English Bulldog", 2);

        print(Jimmy.dogProfile());
    }
Ejemplo n.º 9
0
        public DogDetailsDTO getDogDetailsById(int dogId)
        {
            Dog dog = context.Dog.Where(d => d.DogId == dogId).FirstOrDefault();

            if (dog == null)
            {
                throw new AppException("Nie odnaleziono psa");
            }
            DogBreed breed = context.DogBreed.Where(db => db.BreedId == dog.BreedId).FirstOrDefault();

            if (breed == null)
            {
                throw new AppException("Nie odnaleziono rasy");
            }
            DogClass classD = context.DogClass.Where(c => c.ClassId == dog.ClassId).FirstOrDefault();

            if (classD == null)
            {
                throw new AppException("Nie odnaleziono klasy");
            }
            string        sex        = dog.Sex == "M" ? "Pies" : "Suka";
            DogDetailsDTO dogDetails = new DogDetailsDTO
            {
                dogId              = dog.DogId,
                name               = dog.Name,
                lineageNumber      = dog.LineageNumber,
                registrationNumber = dog.RegistrationNumber,
                titles             = dog.Titles,
                chipNumber         = dog.ChipNumber,
                breedName          = breed.NamePolish,
                sex            = sex,
                birthday       = dog.Birthday,
                fatherName     = dog.FatherName,
                motherName     = dog.MotherName,
                breederName    = dog.BreederName,
                breederAddress = dog.BreederAddress,
                className      = classD.NamePolish
            };

            return(dogDetails);
        }
Ejemplo n.º 10
0
        //Create,add new dog to database
        public void CreateDog(DogClass dog)
        {
            using (SqlConnection sqlconn = new SqlConnection(mainconn))
            {
                SqlCommand sqlcomm = new SqlCommand("CreateDog", sqlconn);
                sqlcomm.CommandType = CommandType.StoredProcedure;

                //pass in the dogclass model properties
                sqlcomm.Parameters.AddWithValue("@DogName", dog.Name);
                sqlcomm.Parameters.AddWithValue("@Breed", dog.Breed);
                sqlcomm.Parameters.AddWithValue("@Gender", dog.Gender);
                sqlcomm.Parameters.AddWithValue("@Comment", dog.Comment);

                //open db connection
                sqlconn.Open();
                //Excute or invoke the CreateDog stored procedure
                sqlcomm.ExecuteNonQuery();
                //Close db connection
                sqlconn.Close();
            }
        }
Ejemplo n.º 11
0
    // Use this for initialization
    void Start()
    {
        DogClass Mr8   = new DogClass(1, 0.6f, 20f, true, "Mr8", "Husky", "White");
        DogClass Kahn  = new DogClass(3, 0.3f, 5f, true, "Kahn", "Teddy", "brown");
        DogClass Forty = new DogClass(2, 0.5f, 10f, false, "Forty", "Hybrid", "Yellow");
        DogClass Leo   = new DogClass(7, 0.8f, 22f, true, "Leo", "Golden Retriever", "Golden");


        mydog.Add(Mr8);
        mydog.Add(Kahn);
        mydog.Add(Forty);
        mydog.Add(Leo);

        Debug.Log("I have " + mydog.Count + " dogs, they are " + mydog[0].Name + ", " + mydog[1].Name + ", " + mydog[2].Name + " and " + mydog[3].Name);

        for (int a = 0; a < mydog.Count; a++)
        {
            Debug.Log(mydog[a].Name + " is a " + mydog[a].Breeds + " and its color is " + mydog[a].Color + ", it is " +
                      mydog[a].Age + " years old.");
        }



        //Write a for loop
        for (int i = 0; i < s1.students.Count; i++)
        {
            Debug.Log("Student " + (i + 1) + " of RC3 is " + s1.students[i]);
        }


        if (j < s1.students.Count)
        {
            Debug.Log(s1.students[j] + " is an RC3 student.");
        }
        else
        {
            Debug.Log("There are no " + j + " students in RC3");
        }
    }
Ejemplo n.º 12
0
    //START
    // Start is called before the first frame update
    void Start()
    {
        //CONDITION
        if (isSunny == true)
        {
            Debug.Log("The weather is sunny today!");
        }
        else
        {
            Debug.Log("The weather is rainny today!");
        }


        //LOOP
        // For example
        for (int i = 0; i < myNumberArray.Length; i++)
        {
            if (myNumberArray[i] == 4)
            {
                Debug.Log("There's a 4 here");
            }
            else
            {
                Debug.Log("There's no 4 here");
            }
        }

        // Foreach example
        foreach (int i in myNumberArray)
        {
            Debug.Log("it works");
        }

        //DOG CLASS
        rex   = new DogClass("rex", 5, "male");
        pongo = new DogClass("pongo", 10, "male");
        milly = new DogClass("milly", 4, "female");
    }
Ejemplo n.º 13
0
        public ContestDetailsDTO getContest(int id)
        {
            ContestDetailsDTO contestDetails;
            ContestType       contestType = context.ContestType.Where(ct => ct.ContestTypeId == id).FirstOrDefault();

            if (contestType == null)
            {
                throw new AppException("Nie odnaleziono konkursu o podanym id");
            }

            List <BreedInfoDTO>         allowedBreeds = new List <BreedInfoDTO>();
            List <AllowedBreedsContest> allowed       = context.AllowedBreedsContest.Where(abc => abc.ContestTypeId == id).ToList();

            foreach (AllowedBreedsContest abc in allowed)
            {
                DogBreed breed = context.DogBreed.Where(db => db.BreedId == abc.BreedTypeId).FirstOrDefault();
                allowedBreeds.Add(new BreedInfoDTO
                {
                    breedId = abc.BreedTypeId,
                    name    = breed.NamePolish
                });
            }

            List <ParticipationInfoDTO> participations = new List <ParticipationInfoDTO>();
            List <Participation>        part           = context.Participation.Where(p => p.ContestId == id).ToList();

            foreach (Participation p in part)
            {
                Dog      dog    = context.Dog.Where(d => d.DogId == p.DogId).FirstOrDefault();
                DogBreed breed  = context.DogBreed.Where(db => db.BreedId == dog.BreedId).FirstOrDefault();
                Grade    grade  = context.Grade.Where(g => g.GradeId == p.GradeId).FirstOrDefault();
                DogClass classD = context.DogClass.Where(c => c.ClassId == dog.ClassId).FirstOrDefault();
                string   place  = (p.Place == null) ? "Nie przyznano" : p.Place.ToString();
                if (grade == null)
                {
                    participations.Add(new ParticipationInfoDTO
                    {
                        participationId = p.ParticipationId,
                        dogId           = p.DogId,
                        name            = dog.Name,
                        breedName       = breed.NamePolish,
                        className       = classD.NamePolish,
                        chipNumber      = dog.ChipNumber,
                        gradeId         = 0,
                        grade           = "Nie oceniono",
                        place           = place,
                        description     = p.Description
                    });
                }
                else
                {
                    participations.Add(new ParticipationInfoDTO
                    {
                        participationId = p.ParticipationId,
                        dogId           = p.DogId,
                        name            = dog.Name,
                        breedName       = breed.NamePolish,
                        className       = classD.NamePolish,
                        chipNumber      = dog.ChipNumber,
                        gradeId         = grade.GradeId,
                        grade           = grade.NamePolish,
                        place           = place,
                        description     = p.Description
                    });
                }
            }

            Contest contest = context.Contest.Where(c => c.ContestTypeId == id).FirstOrDefault();

            if (contest == null)
            {
                contestDetails = new ContestDetailsDTO
                {
                    contestTypeId = contestType.ContestTypeId,
                    contestId     = -1,
                    name          = contestType.NamePolish,
                    isEnterable   = Convert.ToBoolean(contestType.Enterable),
                    placeId       = -1,
                    placeName     = null,
                    startDate     = new DateTime(),
                    endDate       = new DateTime(),
                    allowedBreeds = allowedBreeds,
                    participants  = participations
                };
            }
            else
            {
                Place place = context.Place.Where(p => p.PlaceId == contest.PlaceId).FirstOrDefault();
                contestDetails = new ContestDetailsDTO
                {
                    contestTypeId = contestType.ContestTypeId,
                    contestId     = contest.ContestId,
                    name          = contestType.NamePolish,
                    isEnterable   = Convert.ToBoolean(contestType.Enterable),
                    placeId       = contest.PlaceId,
                    placeName     = place.Name,
                    startDate     = contest.StartDate,
                    endDate       = contest.EndDate,
                    allowedBreeds = allowedBreeds,
                    participants  = participations
                };
            }
            return(contestDetails);
        }
Ejemplo n.º 14
0
        public Dog GenerateDog(int power, int experience)
        {
            var rnd = new Random(Guid.NewGuid().GetHashCode());
            var dog = new Dog();

            var remainingChance = (power * 0.01F);
            var randomRoll      = rnd.Next(0, 6);

            switch (randomRoll)
            {
            case 0:
                dog.dog_class = (int)DogClasses.Guardian;

                dog.defense     = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.health      = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.atk_power   = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.will        = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.prayer      = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.intelligence = _rollStat(remainingChance);
                break;

            case 1:
                dog.dog_class = (int)DogClasses.Champion;

                dog.health      = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.atk_power   = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.defense     = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.will        = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.prayer      = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.intelligence = _rollStat(remainingChance);
                break;

            case 2:
                dog.dog_class = (int)DogClasses.Paladin;

                dog.prayer      = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.will        = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.intelligence = _rollStat(remainingChance);
                remainingChance  = remainingChance / StatPenaltyScaling;

                dog.health      = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.defense     = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.atk_power = _rollStat(remainingChance);
                break;

            case 3:
                dog.dog_class = (int)DogClasses.Assassin;

                dog.atk_power   = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.will        = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.prayer      = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.defense     = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.intelligence = _rollStat(remainingChance);
                remainingChance  = remainingChance / StatPenaltyScaling;

                dog.health = _rollStat(remainingChance);
                break;

            case 4:
                dog.dog_class = (int)DogClasses.Warlock;

                dog.will        = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.defense     = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.health      = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.intelligence = _rollStat(remainingChance);
                remainingChance  = remainingChance / StatPenaltyScaling;

                dog.prayer      = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.atk_power = _rollStat(remainingChance);
                break;

            case 5:
                dog.dog_class = (int)DogClasses.Elementalist;

                dog.intelligence = _rollStat(remainingChance);
                remainingChance  = remainingChance / StatPenaltyScaling;

                dog.will        = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.health      = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.prayer      = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.defense     = _rollStat(remainingChance);
                remainingChance = remainingChance / StatPenaltyScaling;

                dog.atk_power = _rollStat(remainingChance);
                break;
            }

            var classBonus = DogClass.GetClassBonus((DogClasses)dog.dog_class);

            dog.prayer       = Math.Min(200, Math.Max(0, (int)(dog.prayer * classBonus.PrayerScaling)));
            dog.atk_power    = Math.Min(200, Math.Max(0, (int)(dog.atk_power * classBonus.AtkPowerScaling)));
            dog.defense      = Math.Min(200, Math.Max(0, (int)(dog.defense * classBonus.DefenseScaling)));
            dog.health       = Math.Min(200, Math.Max(0, (int)(dog.health * classBonus.HealthScaling)));
            dog.intelligence = Math.Min(200, Math.Max(0, (int)(dog.intelligence * classBonus.IntelligenceScaling)));
            dog.will         = Math.Min(200, Math.Max(0, (int)(dog.will * classBonus.WillScaling)));

            dog.name       = _ng.GenerateDogName(ref dog);
            dog.experience = experience;


            dog.image_path = "https://random.dog/" + DogPictures[rnd.Next(DogPictures.Count)];


            return(dog);
        }