public IActionResult TraerMascota(int id) { try { Mascota mascota = mascotaService.TraerMascota(id); string nombreImg = mascotaService.TraerAvatarMascota(mascota.IdMascota); List <string> totalfotosDeMascota = imagenMascotaService.TraerFotosMascota(mascota.IdMascota); MascotaViewModel mascotaViewModel = new MascotaViewModel { IdMascota = mascota.IdMascota, Nombre = mascota.Nombre, DescripcionRaza = mascotaService.TraeDescripcionRaza(mascota.IdRaza), Avatar = nombreImg, Perdida = mascota.Perdida, Entrenado = totalfotosDeMascota.Count(), ClaseEntrenada = mascota.Entrenada }; return(this.Ok(mascotaViewModel)); } catch (Exception e) { this.logErroresService.LogError(e.Message + " " + e.InnerException + " " + e.TargetSite + " " + this.GetType().ToString().Split('.')[2]); throw; } }
public ActionResult Edit([Bind(Include = "Id,Nombre,Apodo,Fecha_nac,Sexo,Foto,ClienteId,RazaId")] MascotaViewModel mascotaVm) { if (ModelState.IsValid) { var mascota = mascotaVm.BindItem(); db.Entry(mascota).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ClienteId = new SelectList(db.Users, "Id", "Nombre", mascotaVm.ClienteId); ViewBag.RazaId = new SelectList(db.Razas, "Id", "Nombre", mascotaVm.RazaId); return(View(mascotaVm)); }
//private ApplicationDbContext appDb = new ApplicationDbContext(); // GET: Mascotas public ActionResult Index() { var model = new MascotaViewModel(); var query = db.Mascotas.Include(m => m.Cliente).Include(m => m.Raza); var userId = User.Identity.GetUserId().ToString(); if (!User.IsInRole("Admin")) { query = query.Where(x => x.ClienteId == userId); } model.LoadModelList(query.ToList()); //var mascotas = db.Mascotas.Include(m => m.Cliente).Include(m => m.Raza).ToList(); return(View(model)); }
public ActionResult Create([Bind(Include = "Id,Nombre,Apodo,Fecha_nac,Sexo,Foto,ClienteId,RazaId")] MascotaViewModel mascotaVm) { if (ModelState.IsValid) { var mascota = mascotaVm.BindItem(); mascota.Id = Guid.NewGuid(); db.Mascotas.Add(mascota); db.SaveChanges(); return(RedirectToAction("Index")); } //ViewBag.ClienteId = new SelectList(db.Users, "Id", "Nombre", mascotaVm.ClienteId); ViewBag.RazaId = new SelectList(db.Razas, "Id", "Nombre", mascotaVm.RazaId); ViewBag.ClienteId = User.Identity.Name; return(View(mascotaVm)); }
public async Task <Mascota> ToMascotaAsync(MascotaViewModel Model, string Ruta, bool EsNuevo) { Mascota Mascota = new Mascota { Agendas = Model.Agendas, Nacimiento = Model.Nacimiento, Historias = Model.Historias, Id = EsNuevo ? 0 : Model.Id, ImagenUrl = Ruta, Nombre = Model.Nombre, Propietario = await _DataContext.Propietarios.FindAsync(Model.PropietarioId), TipoMascota = await _DataContext.TipoMascotas.FindAsync(Model.TipoMascotaId), Raza = Model.Raza, Comentarios = Model.Comentarios }; return(Mascota); }
// GET: Mascotas/Details/5 public ActionResult Details(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Mascota mascota = db.Mascotas.Find(id); if (mascota == null) { return(HttpNotFound()); } var model = new MascotaViewModel(); model.LoadModel(mascota); return(View(model)); }
// GET: Mascotas/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Mascota mascota = db.Mascotas.Find(id); if (mascota == null) { return(HttpNotFound()); } var model = new MascotaViewModel(); model.LoadModel(mascota); ViewBag.ClienteId = new SelectList(db.Users, "Id", "Nombre", mascota.ClienteId); ViewBag.RazaId = new SelectList(db.Razas, "Id", "Nombre", mascota.RazaId); return(View(model)); }
public async Task <IActionResult> EditMascota(MascotaViewModel Model) { if (ModelState.IsValid) { string Ruta = string.Empty; if (Model.ArchivoImagen != null) { Ruta = await _ImagenHelper.UploadImageAsync(Model.ArchivoImagen); } Mascota Mascota = await _ConverterHelper.ToMascotaAsync(Model, Ruta, false); _Context.Mascotas.Update(Mascota); await _Context.SaveChangesAsync(); return(new RedirectResult(HttpUtility.UrlDecode((Url.Action($"Details/{Model.PropietarioId}", "Propietarios"))))); } Model.TipoMascotas = _ComboHelper.GetComboTipoMascota(); return(View(Model)); }
public async Task <IActionResult> AddMascota(int?id) { if (id == null) { return(NotFound()); } Propietario Propietario = await _Context.Propietarios.FindAsync(id.Value); if (Propietario == null) { return(NotFound()); } MascotaViewModel Model = new MascotaViewModel { Nacimiento = DateTime.Today, PropietarioId = Propietario.Id, TipoMascotas = _ComboHelper.GetComboTipoMascota() }; return(View(Model)); }