public IActionResult AddEditAnimal(int?id) { AnimalVM model = new AnimalVM(); if (id.HasValue) { AnimalRegistration feed = _repo.AnimalRegistration.GetById(id.Value); if (feed != null) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <AnimalRegistration, AnimalVM>(); }); IMapper iMapper = config.CreateMapper(); model = iMapper.Map <AnimalRegistration, AnimalVM>(feed); } } model.speciess = new SelectList(_repo.Species.GetModel(), "id", "speciesName"); model.breeds = new SelectList(_repo.Breed.GetModel(), "id", "breedNameShort"); model.owners = new SelectList(_repo.OwnerKeeper.GetModel(), "id", "fullName"); model.farms = new SelectList(_repo.Farm.GetModel(), "id", "orgtanizationName"); model.keepers = new SelectList(_repo.keepers.GetModel(), "id", "fullName"); model.dams = new SelectList(_repo.AnimalRegistration.GetModel().Where(m => m.gender == "Male"), "id", "earTagNo"); model.sires = new SelectList(_repo.AnimalRegistration.GetModel().Where(m => m.gender == "Female"), "id", "earTagNo"); model.id = 0; model.declaredDate = DateTime.Now.Date; return(View(model)); }
public async Task <IActionResult> Upsert(int?id) { IEnumerable <ScientificClass> scList = await _scRepository.GetAllAsync(StaticNames.ScientificClassAPIPath); AnimalVM animalVM = new AnimalVM() { ScientificClass = scList.Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }), Animal = new Animal() }; if (id == null) { //this will be true for create or insert return(View(animalVM)); } //Flow will come here for update animalVM.Animal = await _animalRepository.GetAsync(StaticNames.AnimalAPIPath, id.GetValueOrDefault()); if (animalVM.Animal == null) { return(NotFound()); } return(View(animalVM)); }
// GET: AnimalEcosystemDetail public ActionResult Index() { EcoGameModelContainer DB = new EcoGameModelContainer(); List <AnimalVM> AnimalVMList = new List <AnimalVM>(); var AnimalList = (from Ani in DB.AnimalSet join Eco in DB.EcosystemSet on Ani.Ecosystem.EcosystemId equals Eco.EcosystemId select new { Ani.AnimalId, Ani.NameAnimal, Ani.ImgAnimal, Ani.SoundAnimal, Ani.DescAnimal, Eco.NameEcosystem } ).ToList(); foreach (var item in AnimalList) { AnimalVM objcvm = new AnimalVM(); objcvm.AnimalId = item.AnimalId; objcvm.NameAnimal = item.NameAnimal; objcvm.ImgAnimal = item.ImgAnimal; objcvm.SoundAnimal = item.SoundAnimal; objcvm.DescAnimal = item.DescAnimal; objcvm.NameEcosystem = item.NameEcosystem; AnimalVMList.Add(objcvm); } return(View(AnimalVMList)); }
public async Task <IActionResult> Upsert(AnimalVM obj) { if (ModelState.IsValid) { var files = HttpContext.Request.Form.Files; if (files.Count > 0) { byte[] p1 = null; using (var fs1 = files[0].OpenReadStream()) { using (var ms1 = new MemoryStream()) { fs1.CopyTo(ms1); p1 = ms1.ToArray(); } } obj.Animal.Picture = p1; } else { var objFromDb = await _animalRepository.GetAsync(StaticNames.AnimalAPIPath, obj.Animal.Id); if (objFromDb != null) { if (objFromDb.Picture != null) { obj.Animal.Picture = objFromDb.Picture; } } } if (obj.Animal.Id == 0) { await _animalRepository.CreateAsync(StaticNames.AnimalAPIPath, obj.Animal); } else { await _animalRepository.UpdateAsync(StaticNames.AnimalAPIPath + obj.Animal.Id, obj.Animal); } return(RedirectToAction(nameof(Index))); } else { IEnumerable <ScientificClass> scList = await _scRepository.GetAllAsync(StaticNames.ScientificClassAPIPath); AnimalVM animalVM = new AnimalVM() { ScientificClass = scList.Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }), Animal = obj.Animal }; return(View(animalVM)); } }
public ActionResult Create(AnimalVM animalVM) { if (animalVM.Id > 0) WebApiClient.Build().Put(EndPoints.Animals, animalVM.Id, animalVM); else WebApiClient.Build().Post(EndPoints.Animals, animalVM); return RedirectToAction("List"); }
public Listado_Sincronizacion() { InitializeComponent(); comApi = new ComunicacionApi(); //primer linea a usar Animales = new ObservableCollection <ItemSeleccionable <Animal> >(); AnimalParaAgregar = new List <Animal>(); Lista_Item = new List <Item>(); animalvm = new AnimalVM(); }
public ActionResult Edit(AnimalVM animalVM) { animalVM.Animal.TypeName = animalVM.ChosenAnimalType; if (AnimalRepo.EditAnimal(animalVM.Animal)) { return(RedirectToAction("Index")); } animalVM.AnimalTypes = AnimalRepo.GetAnimalTypes(); return(View(animalVM)); }
public ActionResult Create(int? id) { AnimalVM animal = new AnimalVM(); animal.Races = WebApiClient.Build().Get<List<RaceVM>>(EndPoints.Races, null); if (id != null) { animal = WebApiClient.Build().Get<AnimalVM>(EndPoints.Animals, id); } return View(animal); }
public ActionResult UpdateAnimal(int id) { var result = db.Animal.FirstOrDefault(x => x.ID == id); AnimalVM animal = new AnimalVM(); animal.Name = result.Name; animal.ID = result.ID; animal.Age = result.Age; animal.Color = result.Color; animal.Location = result.Location; animal.GenusName = AnimalRepo.AnimalGenusName(result.GenusId); animal.CategoryName = AnimalRepo.AnimalCategoryName(result.CategoryId); return(View(animal)); }
public ActionResult UpdateAnimal(AnimalVM model) { if (ModelState.IsValid) { var result = db.Animal.FirstOrDefault(x => x.ID == model.ID); result.Name = model.Name; result.Description = model.Description; result.Color = model.Color; result.Location = model.Location; result.Age = model.Age; result.ID = model.ID; result.GenusId = AnimalRepo.AnimalGenus(model.GenusName); result.CategoryId = AnimalRepo.AnimalCategory(model.CategoryName); ViewBag.islemDurum = 1; db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.islemDurum = 2; return(View()); } }
public ActionResult AddEditAnimal(int?id, [FromForm] AnimalVM model, IFormFile file) { try { if (ModelState.IsValid) { bool isNew = !id.HasValue; if (isNew) { //var config = new MapperConfiguration(cfg => //{ // cfg.CreateMap<AnimalVM, AnimalRegistration>(); //}); //IMapper iMapper = config.CreateMapper(); AnimalRegistration animal = _mapper.Map <AnimalRegistration>(model); animal.createdAt = DateTime.Now.ToShortDateString(); animal.EarTag = _repo.EarTag.GetByTag(model.earTagNo); animal.earTagId = animal.EarTag.id; _repo.AnimalRegistration.Insert(animal); _repo.Save(); var path = _host.WebRootPath + "\\images\\animal\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (file != null) { var fileName = Path.Combine(path, animal.earTagNo + ".jpg"); file.CopyTo(new FileStream(fileName, FileMode.Create)); } } else { AnimalRegistration animal = _mapper.Map <AnimalRegistration>(model); animal.EarTag = _repo.EarTag.GetByTag(model.earTagNo); animal.earTagId = animal.EarTag.id; animal.updatedBy = "admin"; _repo.AnimalRegistration.Update(animal); } } else { //model.speciess = new SelectList(_repo.Species.GetModel(), "id", "speciesName", model.speciesId); //model.breeds = new SelectList(_repo.Breed.GetModel(), "id", "breedNameShort", model.breedId); //model.owners = new SelectList(_repo.OwnerKeeper.GetModel(), "id", "fullName", model.ownerId); //model.keepers = new SelectList(_repo.keepers.GetModel(), "id", "fullName", model.keeperId); //model.farms = new SelectList(_repo.Farm.GetModel(), "id", "orgtanizationName", model.farmId); //model.dams = new SelectList(_repo.AnimalRegistration.GetModel().Where(m => m.gender == "Male"), "id", "earTagNo", model.damId); //model.sires = new SelectList(_repo.AnimalRegistration.GetModel().Where(m => m.gender == "Female"), "id", "earTagNo", model.sireId); model.declaredDate = DateTime.Now.Date; return(BadRequest(model)); } } catch (Exception ex) { throw ex; } // AnimalRegistration animal = _repo.AnimalRegistration. return(Ok(model)); }