Inheritance: MonoBehaviour
Example #1
0
        /*
         * OperationResult IRepository.Delete<T>(T t)
         * {
         *     throw new NotImplementedException();
         * }
         */

        OperationResult IRepository.Delete(animal animal, string str)
        {
            OperationResult opResult = new OperationResult();

            if (animal != null && string.IsNullOrEmpty(animal.full_name))
            {
                return(null);
            }

            animal existAnimal = DBContext.Animals.FirstOrDefault(c => c.full_name == animal.full_name);

            if (existAnimal == null)
            {
                return(null);
            }
            try
            {
                DBContext.Animals.Remove(existAnimal);
                DBContext.SaveChanges();
            }
            catch (Exception ex)
            {
                opResult.SetException(ex);
            }

            return(opResult);
        }
Example #2
0
        //ajouter un animal
        public bool Ajouter(string Nom, int Quantite, string Type, string Sexe, int idcat)
        {
            Animal                 = new animal();
            Animal.nom_animal      = Nom;
            Animal.quantite_animal = Quantite;
            Animal.type_animal     = Type;
            Animal.sexe_animal     = Sexe;
            Animal.id_category     = idcat;

            //si l'animal existe dans la base de données
            var exist = db.animals.SingleOrDefault(s => s.nom_animal == Nom);

            if (exist == null)
            {
                //l'ajout dans la base de données
                db.animals.Add(Animal);
                //sauvgarde de base
                db.SaveChanges();
                db.GetValidationErrors();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
 public ActionResult Edit([Bind(Include = "id,codigo_sag,sexo,fec_nac,fecha_ing,tipo_id,raza_id,estado_id")] animal animal)
 {
     if (ModelState.IsValid)
     {
         if (animal.fec_nac > animal.fecha_ing)
         {
             ViewBag.Error = "Fecha de nacimiento no debe ser superior a la de ingreso al fundo";
         }
         else
         {
             DateTime?hoy = DateTime.Today;
             if (animal.fec_nac > hoy || animal.fecha_ing > hoy)
             {
                 ViewBag.Error = "Las fechas ingresadas no deben superar el dia actual";
             }
             else
             {
                 db.Entry(animal).State = EntityState.Modified;
                 db.SaveChanges();
                 return(RedirectToAction("Index"));
             }
         }
     }
     ViewBag.estado_id = new SelectList(db.estado, "id", "nombre", animal.estado_id);
     ViewBag.raza_id   = new SelectList(db.raza, "id", "nombre", animal.raza_id);
     ViewBag.tipo_id   = new SelectList(db.tipo, "id", "nombre", animal.tipo_id);
     return(View(animal));
 }
Example #4
0
    public static void module02()
    {
        person person1 = new person();

        person1.personInfo("John Doe", 37);

        WriteLine(person1.Name);
        WriteLine(person1.Age);
        person1.ageInfo();
        person1.Name = "Brittany";
        WriteLine(person1.Name);
        WriteLine();
        string[] words = new string[] { "An array ", "can hold ", "various objects of", " the same type" };

        for (int i = 0; i < words.Length; i++)
        {
            Write(words[i]);
        }

        animal cheetah = new animal();

        cheetah.Species = "Cheetah";
        cheetah.Name    = "Checkers";
        cheetah.Attack  = "Speed and claws";
        WriteLine("\nStructs");
        WriteLine(cheetah.Species);
        WriteLine(cheetah.Name);
        WriteLine(cheetah.Attack);
    }
Example #5
0
        public JsonResult ConsultaQR(string cod_sag)
        {
            animal            animalBd      = new animal();
            AnimalJsonRequest animalRequest = new AnimalJsonRequest();

            if (cod_sag != null)
            {
                animalBd = db.animal.Include(a => a.tipo).Include(a => a.raza).SingleOrDefault(a => a.codigo_sag == cod_sag);
                if (animalBd != null)
                {
                    animalRequest.id         = animalBd.id;
                    animalRequest.codigo_sag = animalBd.codigo_sag;
                    animalRequest.tipo       = animalBd.tipo.nombre;
                    animalRequest.raza       = animalBd.raza.nombre;
                    animalRequest.sexo       = animalBd.sexo;
                }
                else
                {
                    return(null);
                }


                var      today   = DateTime.Today;
                DateTime nac_fec = Convert.ToDateTime(animalBd.fec_nac);
                var      age     = today.Year - nac_fec.Year;
                animalRequest.edad = age;
            }
            return(Json(animalRequest, JsonRequestBehavior.AllowGet));
        }
Example #6
0
        /// <summary>
        /// retorna  objeto do tipo animal com o mair tempo se adoção.
        /// </summary>
        /// <returns>animal</returns>
        public animal Getanimallongtime()
        {
            animal animal = null;

            try
            {
                //Instancia classe de acesso a dados.
                DbDesafioCastContext obj = new DbDesafioCastContext();

                List <animal> list = obj.animals.ToList();

                //ordena a lista de forma decrecente pelo id de registro.
                var listaOrdenada = list.OrderBy(e => e.Id);

                //procura pelo primeiro animal que deu entrada no banco.
                foreach (animal lista in listaOrdenada)
                {
                    if (Getadotado(lista.Id) == true)
                    {
                        animal = lista;
                        break;
                    }
                }

                return(animal);
            }
            catch
            {
                return(animal);
            }
        }
Example #7
0
        private void btnmodanimal_Click(object sender, EventArgs e)
        {
            animal Animal = new animal();

            if (selection() != null)
            {
                MessageBox.Show(selection(), "selectionner", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Forms.Add_edit_animal frmanimal = new Forms.Add_edit_animal(this);
                frmanimal.titreanimal.Text = "Modifier Animal";
                for (int i = 0; i < gridanimal.Rows.Count; i++)
                {
                    //si la ligne est selectionné
                    if ((bool)gridanimal.Rows[i].Cells[0].Value == true)
                    {
                        if (Animal != null)
                        {
                            frmanimal.ID_animal            = (int)gridanimal.Rows[i].Cells[1].Value;
                            frmanimal.txtnoma.Text         = gridanimal.Rows[i].Cells[2].Value.ToString();
                            frmanimal.txtquantité.Text     = gridanimal.Rows[i].Cells[3].Value.ToString();
                            frmanimal.txttype.Text         = gridanimal.Rows[i].Cells[4].Value.ToString();
                            frmanimal.txtsexea.Text        = gridanimal.Rows[i].Cells[5].Value.ToString();
                            frmanimal.combocategoriey.Text = gridanimal.Rows[i].Cells[6].Value.ToString();
                        }
                    }
                }
                frmanimal.ShowDialog();
            }
        }
Example #8
0
        public void AddSoundsByAnimal(animal animal, Sound sound)
        {
            if (ExistsSound(sound))
            {
                return;
            }

            switch (animal)
            {
            case animal.Frog:
                _frogSounds.Add(sound);
                break;

            case animal.Dragonfly:
                _dragonflySounds.Add(sound);
                break;

            case animal.Cricket:
                _cricketSounds.Add(sound);
                break;

            default:
                break;
            }
        }
Example #9
0
    // Use this for initialization
    void Start()
    {
        Vector3 pos = new Vector3(Random.Range(ranges[0].position.x, ranges[1].position.x), Random.Range(ranges[2].position.y, ranges[3].position.y), 0);

        Instantiate(animal, pos, transform.rotation);
        animalScript = FindObjectOfType <animal>();
        animalScript.setRange(ranges[1].position.x, ranges[3].position.y, ranges[0].position.x, ranges[2].position.y);
    }
Example #10
0
	animal changeAnimal(animal ani)
	{
		if(ani == animal.dog)
			ani = animal.cat;
		else if (ani == animal.cat)
			ani = animal.dog;
		return ani;
	}
Example #11
0
        public ActionResult DeleteConfirmed(int id)
        {
            animal animal = db.animals.Find(id);

            db.animals.Remove(animal);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #12
0
        static void Main1(string[] args)
        {
            dog    mydog  = new dog();
            animal thePet = mydog;

            thePet.sound();//.eat();
            mydog.sound();
        }
Example #13
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            int id = int.Parse(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value.ToString());
            veterinariaEntities db = new veterinariaEntities();
            animal anim            = db.animal.Find(id);

            db.animal.Remove(anim);
            db.SaveChanges();
            refrescar();
        }
Example #14
0
 public ActionResult Edit([Bind(Include = "idAnimal,Nome,Descricao,Peso,Idade")] animal animal)
 {
     if (ModelState.IsValid)
     {
         db.Entry(animal).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(animal));
 }
        public ActionResult AnimalFacts()
        {
            ViewBag.Message = "animal fact page.";
            animal an = new animal();

            an.Aname   = "Lion";
            an.AType   = "Mammal";
            an.Pop     = 2500;
            an.ADietry = "Carnivore";
            return(View("Animal", an));
        }
Example #16
0
        private void Editar_Load(object sender, EventArgs e)
        {
            veterinariaEntities db = new veterinariaEntities();
            animal objAnimal       = db.animal.Find(id);

            txtNombre.Text     = objAnimal.nombre;
            txtEdad.Text       = Convert.ToString(objAnimal.edad);
            txtEspecie.Text    = objAnimal.especie;
            txtPeso.Text       = Convert.ToString(objAnimal.peso);
            labelOcultoId.Text = Convert.ToString(objAnimal.id);
        }
Example #17
0
        public ActionResult Create([Bind(Include = "idAnimal,Nome,Descricao,Peso,Idade")] animal animal)
        {
            if (ModelState.IsValid)
            {
                db.animals.Add(animal);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(animal));
        }
Example #18
0
 public ActionResult Edit([Bind(Include = "Id,nome,idade,sexo,dataEntrada,racaId")] animal animal)
 {
     if (ModelState.IsValid)
     {
         db.Entry(animal).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.racaId = new SelectList(db.racas, "id", "nomeraca", animal.racaId);
     return(View(animal));
 }
Example #19
0
 public ActionResult Edit([Bind(Include = "id,texto,urlImagem,Usuario_id")] animal animal)
 {
     if (ModelState.IsValid)
     {
         db.Entry(animal).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Usuario_id = new SelectList(db.usuario, "id", "nome", animal.Usuario_id);
     return(View(animal));
 }
Example #20
0
    void Start()
    {
        ArrayList myArrayList      = new ArrayList();
        ArrayList anotherArrayList = new ArrayList();

        //添加对象
        //第一种添加方式
        myArrayList.Add(new human("Tom"));
        //第二种添加方式
        animal myAnimal = new animal();

        myAnimal.name = "Cow";
        myArrayList.Add(myAnimal);
        //第三种添加方式
        myArrayList.Insert(2, new human("Jerry"));
        //返回成员数量
        print("Amount of members: " + myArrayList.Count);
        //返回成员编号
        print("Index of myAnimal is: " + myArrayList.IndexOf(myAnimal));
        //添加另一个ArrayList
        anotherArrayList.Add(new human("Mary"));
        anotherArrayList.Add(new human("Jack"));
        myArrayList.AddRange(anotherArrayList);
        print("Amount of members: " + myArrayList.Count);
        //访问成员
        print("#2 member in the Array list is: " + ((human)myArrayList[2]).name);
        //删除一个成员
        myArrayList.Remove(myAnimal);
        myArrayList.RemoveAt(0);
        print("Amount of members: " + myArrayList.Count);
        print("#0 member in the Array list is: " + ((human)myArrayList[0]).name);
        //使用foreach循环
        myArrayList.Add(new human("Susan"));
        myArrayList.Add(new human("Mike"));
        myArrayList.Add(new human("Lucy"));
        foreach (human iterator in myArrayList)
        {
            print(iterator.name);
        }
        //若其中包含有其它类型的对象,则原来的foreach命令便会抛出异常
        myArrayList.Add(myAnimal);
        //foreach (human iterator in myArrayList) { print(iterator.name); }
        foreach (System.Object iterator in myArrayList)
        {
            if (iterator is human)
            {
                print("Human: " + ((human)iterator).name);
            }
            else
            {
                print("Animal: " + ((animal)iterator).name);
            }
        }
    }
Example #21
0
    public void CreateRandomAnimal()
    {
        animal v     = new animal(0);
        int    index = units.add(v);

        if (index >= 0)
        {
            ((animal)units.get(index)).create(index);
            ((animal)units.get(index)).spawn(100, 100);
            //((animal)units.get(index)).ai.wander(true);
        }
    }
Example #22
0
        public ActionResult Create([Bind(Include = "id,texto,urlImagem,Usuario_id")] animal animal)
        {
            if (ModelState.IsValid)
            {
                db.animal.Add(animal);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Usuario_id = new SelectList(db.usuario, "id", "nome", animal.Usuario_id);
            return(View(animal));
        }
Example #23
0
 //Supprimer un animal
 public void Supprimer(int ID)
 {
     Animal = new animal();
     Animal = db.animals.SingleOrDefault(s => s.id_animal == ID);
     //si le client est existe
     if (Animal != null)
     {
         //Supprimer le client
         db.animals.Remove(Animal);
         //enregistrement sur la base de données
         db.SaveChanges();
     }
 }
Example #24
0
        static void Main(string[] args)
        {
            animal [] animals = new animal [3]; //I create a object animal
            animals[0]  = new cat();            //in array 0 is the method walk from cat class
            animals[1]  = new dog();            // in array 1 is the method walk from dog class
            animals [2] = new cat();            //in array 0 is the method walk from cat class
            //always when I use the class cat or dog, the method walk overrides the abstract method walk from class animal

            foreach (animal t in animals)
            {
                t.walk();
            }
        }
Example #25
0
        // GET: Animal/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            animal animal = db.animal.Find(id);

            if (animal == null)
            {
                return(HttpNotFound());
            }
            return(View(animal));
        }
Example #26
0
        public Reply Delete([FromBody] AnimalViewModel model)
        {
            Reply oReply = new Reply();

            oReply.result = 0;

            // Método de verificación del token
            if (!Verify(model.token))
            {
                oReply.message = "No autorizado";
                return(oReply);
            }

            /* La validación se utiliza del lado del cliente, indicando si esta seguro de eliminar el registro
             * //// Se puede agregar en esta sección validaciones, ej name es obligatorio... usa sección helper indicada más adelante con #
             * //if (!Validate(model)) // se envia model a Validate, si no es true, muestre error
             * //{
             * //    oReply.message = error;
             * //    return oReply;
             * //}
             */

            // 11.2 se agrega try catch
            try
            {
                using (Cursomvc_apiEntities DB = new Cursomvc_apiEntities())
                {
                    // Se crea objeto de la entidad de la db para agregar a la db
                    animal oAnimal = DB.animal.Find(model.id); // Acá cambia a .find en el edit

                    oAnimal.idState = 0;

                    // Se agrega objeto modificado a db
                    DB.Entry(oAnimal).State = System.Data.Entity.EntityState.Modified; // Acà cambia para indicar a db cambio en objeto
                    DB.SaveChanges();

                    // Para respuesta a petición api
                    List <ListAnimalsViewModel> lst = List(DB); // Implementa metodo de helper, que trae resultado en lista, se le pasa como parametro el contexto

                    oReply.result  = 1;
                    oReply.message = "Dato editado: ";
                    oReply.data    = lst; // Para que el cliente no tenga que solicitar nuevamente la data, se remite listado de entidad
                }
            }
            catch (Exception ex)
            {
                oReply.message = "Error, intente nuevamente..." + ex;
            }
            return(oReply);
        }
Example #27
0
        public Reply Add([FromBody] AnimalViewModel model)
        {
            Reply oReply = new Reply();

            oReply.result = 0;

            // Método de verificación del token
            if (!Verify(model.token))
            {
                oReply.message = "No autorizado";
                return(oReply);
            }

            // Se puede agregar en esta sección validaciones, ej name es obligatorio... usa sección helper indicada más adelante con #
            if (!Validate(model)) // se envia model a Validate, si no es true, muestre error
            {
                oReply.message = error;
                return(oReply);
            }

            // 11.2 se agrega try catch
            try
            {
                using (Cursomvc_apiEntities DB = new Cursomvc_apiEntities())
                {
                    // Se crea objeto de la entidad de la db para agregar a la db
                    animal oAnimal = new animal(); // Como se va a crear un nuevo objeto animal, se instancia como new animal el nuevo objeto
                    oAnimal.idState = 1;
                    oAnimal.name    = model.name;
                    oAnimal.patas   = model.patas;

                    // Se agrega objeto a db
                    DB.animal.Add(oAnimal);
                    DB.SaveChanges();

                    // Para respuesta a petición api
                    List <ListAnimalsViewModel> lst = List(DB); // Implementa metodo de helper, que trae resultado en lista, se le pasa como parametro el contexto

                    oReply.result  = 1;
                    oReply.message = "Dato agregado: ";
                    oReply.data    = lst; // Para que el cliente no tenga que solicitar nuevamente la data, se remite listado de entidad
                }
            }
            catch (Exception ex)
            {
                oReply.message = "Error, intente nuevamente..." + ex;
            }
            return(oReply);
        }
Example #28
0
        // GET: animals/Edit/5
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            animal animal = db.animal.Find(id);

            if (animal == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Usuario_id = new SelectList(db.usuario, "id", "nome", animal.Usuario_id);
            return(View(animal));
        }
Example #29
0
        // GET: animals/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            animal animal = db.animals.Find(id);

            if (animal == null)
            {
                return(HttpNotFound());
            }
            ViewBag.racaId = new SelectList(db.racas, "id", "nomeraca", animal.racaId);
            return(View(animal));
        }
Example #30
0
        public Reply Add([FromBody] AnimalViewModel model)
        {
            Reply oR = new Reply();

            oR.result = 0;

            if (!Verify(model.token))
            {
                oR.message = "No autorizado";
                return(oR);
            }
            //vALIDA

            if (!Validate(model))
            {
                oR.message = error;
                return(oR);
            }

            try
            {
                using (mvcApiEntities1 db3 = new mvcApiEntities1())
                {
                    animal oAnimal = new animal();
                    oAnimal.idState = 1;
                    oAnimal.name    = model.Name;
                    oAnimal.patas   = model.Patas;

                    db3.animal.Add(oAnimal);
                    db3.SaveChanges();

                    List <LsitAnimalsViewModel> lst = (from d in db3.animal
                                                       where d.idState == 1
                                                       select new LsitAnimalsViewModel
                    {
                        Name = d.name,
                        Patas = d.patas
                    }).ToList();
                    oR.data   = lst;
                    oR.result = 1;
                }
            }
            catch (Exception ex)
            {
                oR.message = "Ocurrio error del servidor" + ex;
            }
            return(oR);
        }
Example #31
0
        public ActionResult DeleteConfirmed(int id)
        {
            animal animal = db.animal.Find(id);

            try
            {
                db.animal.Remove(animal);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ViewBag.Error = "No se puede eliminar debido a que existen datos asociados a el animal";
            }
            return(View(animal));
        }