Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("IdVacuna,Nombre,Descripcion")] Vacuna vacuna)
        {
            if (id != vacuna.IdVacuna)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vacuna);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VacunaExists(vacuna.IdVacuna))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vacuna));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("IdEstancia,Nombre,Estado")] Estancia estancia)
        {
            if (id != estancia.IdEstancia)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(estancia);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EstanciaExists(estancia.IdEstancia))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(estancia));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("IdPersona,Nombres,Apellidos,Ci,FechaNacimiento,Estado")] Persona persona)
        {
            if (id != persona.IdPersona)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(persona);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonaExists(persona.IdPersona))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(persona));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("IdRelacion,IdProgenitor,IdHijo,Estado")] Relacion relacion)
        {
            if (id != relacion.IdRelacion)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(relacion);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RelacionExists(relacion.IdRelacion))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdHijo"]       = new SelectList(_context.Ganado, "IdGanado", "Tag", relacion.IdHijo);
            ViewData["IdProgenitor"] = new SelectList(_context.Ganado, "IdGanado", "Tag", relacion.IdProgenitor);
            return(View(relacion));
        }
        public async Task <IActionResult> Create([Bind("IdRazonCancelacion,IdOrden,IdCancelacion,Glosa,Estado")] Cancelacion cancelacion)
        {
            if (ModelState.IsValid)
            {
                var ordenCancelada = _context.Orden.Where(orden => orden.IdOrden == cancelacion.IdOrden).First();
                ordenCancelada.Estado = (int)Orden.Estados.Cancelado;
                _context.Update(ordenCancelada);

                _context.Add(cancelacion);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdCancelacion"] = new SelectList(_context.RazonCancelacion, "IdRazonCancelacion", "Nombre", cancelacion.IdCancelacion);
            ViewData["IdOrden"]       = new SelectList(_context.Orden, "IdOrden", "IdOrden", cancelacion.IdOrden);
            return(View(cancelacion));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("IdOrden,FechaPlanificacion,Razon,Estado")] Orden orden)
        {
            var hayPesaje     = (Request.Form["hayPesaje"] == "on");
            var hayInspeccion = (Request.Form["hayInspeccion"] == "on");
            var hayVacunacion = (Request.Form["hayVacunacion"] == "on");
            var seleccionados = (Request.Form["PlanificacionVacunacion"].ToList());

            if (id != orden.IdOrden)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (orden.FechaPlanificacion < DateTime.Now)
                    {
                        return(View("~/Views/Shared/Error.cshtml"));
                    }
                    Pesaje     psj;
                    Vacunacion vcn;
                    Inspeccion nspccn;
                    Conteo     cnt = _context.Conteo.Where(o => o.IdOrden == orden.IdOrden).First();

                    if (_context.Pesaje.Where(o => o.IdOrden == orden.IdOrden).Count() == 0)
                    {
                        psj = null;
                    }
                    else
                    {
                        psj = _context.Pesaje.Where(o => o.IdOrden == orden.IdOrden).First();
                    }

                    if (_context.Vacunacion.Where(o => o.IdOrden == orden.IdOrden).Count() == 0)
                    {
                        vcn = null;
                    }
                    else
                    {
                        vcn = _context.Vacunacion.Where(o => o.IdOrden == orden.IdOrden).First();
                    }

                    if (_context.Inspeccion.Where(o => o.IdOrden == orden.IdOrden).Count() == 0)
                    {
                        nspccn = null;
                    }
                    else
                    {
                        nspccn = _context.Inspeccion.Where(o => o.IdOrden == orden.IdOrden).First();
                    }



                    Abstracciones.OrdenBuilder builder = new Abstracciones.OrdenBuilder(orden);

                    if (hayPesaje)
                    {
                        builder.WithPesaje(true);
                    }
                    else
                    {
                        if (psj != null)
                        {
                            _context.Remove(psj);
                        }
                        builder.WithPesaje(false);
                    }

                    if (hayInspeccion)
                    {
                        builder.WithInspeccion(true);
                    }
                    else
                    {
                        if (nspccn != null)
                        {
                            _context.Remove(nspccn);
                        }
                        builder.WithInspeccion(false);
                    }

                    if (hayVacunacion)
                    {
                        builder.WithVacunacion(true, seleccionados);
                    }
                    else
                    {
                        builder.WithVacunacion(false, null);
                    }



                    if (vcn != null)
                    {
                        foreach (PlanificacionVacunacion plan in _context.PlanificacionVacunacion.Where(o => o.IdVacunacion == vcn.IdVacunacion))
                        {
                            _context.Remove(plan);
                        }
                        _context.Remove(vcn);
                    }


                    orden = builder.GetOrden();
                    using (var transaccion = _context.Database.BeginTransaction())
                    {
                        try
                        {
                            _context.Update(orden);
                            await _context.SaveChangesAsync();

                            cnt.IdOrden = orden.IdOrden;
                            Conteo cont = cnt;
                            _context.Update(cont);

                            if (orden.Inspeccion != null && orden.Inspeccion.Count() != 0)
                            {
                                orden.Inspeccion.First().IdOrden = orden.IdOrden;
                                if (nspccn == null)
                                {
                                }
                                else
                                {
                                    orden.Inspeccion.First().IdInspeccion = nspccn.IdInspeccion;
                                    _context.Update(orden.Inspeccion.First());
                                }
                            }
                            if (orden.Pesaje != null && orden.Pesaje.Count() != 0)
                            {
                                orden.Pesaje.First().IdOrden = orden.IdOrden;
                                if (psj == null)
                                {
                                }
                                else
                                {
                                    orden.Pesaje.First().IdPesaje = psj.IdPesaje;
                                    _context.Update(orden.Inspeccion.First());
                                }
                            }
                            transaccion.Commit();
                        }
                        catch
                        {
                            transaccion.Rollback();
                            return(View("~/Views/Shared/Error.cshtml"));

                            throw;
                        }
                        await _context.SaveChangesAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrdenExists(orden.IdOrden))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }