/* * 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); }
//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); } }
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)); }
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); }
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)); }
/// <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); } }
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(); } }
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; } }
// 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); }
animal changeAnimal(animal ani) { if(ani == animal.dog) ani = animal.cat; else if (ani == animal.cat) ani = animal.dog; return ani; }
public ActionResult DeleteConfirmed(int id) { animal animal = db.animals.Find(id); db.animals.Remove(animal); db.SaveChanges(); return(RedirectToAction("Index")); }
static void Main1(string[] args) { dog mydog = new dog(); animal thePet = mydog; thePet.sound();//.eat(); mydog.sound(); }
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(); }
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)); }
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); }
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)); }
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)); }
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)); }
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); } } }
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); } }
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)); }
//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(); } }
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(); } }
// 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)); }
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); }
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); }
// 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)); }
// 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)); }
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); }
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)); }