public ActionResult Edit([Bind(Include = "Id,TareaId,MascotaId,Fecha_ejec")] TareasMascota tareasMascota)
        {
            if (ModelState.IsValid)
            {
                if (db.TareasMascotas.Count(x => x.MascotaId == tareasMascota.MascotaId && x.Fecha_ejec == tareasMascota.Fecha_ejec) < 5)
                {
                    db.Entry(tareasMascota).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("Fecha_ejec", "Solo puede crear hasta 5 tareas para esta mascota en la fecha seleccionada");
                }
            }

            IQueryable <Mascota> queryMascotas = db.Mascotas;
            var userId = User.Identity.GetUserId().ToString();

            if (!User.IsInRole("Admin"))
            {
                queryMascotas = queryMascotas.Where(x => x.ClienteId == userId);
            }

            ViewBag.MascotaId = new SelectList(queryMascotas, "Id", "Nombre", tareasMascota.MascotaId);
            ViewBag.TareaId   = new SelectList(db.Tareas, "Id", "Nombre", tareasMascota.TareaId);
            return(View(tareasMascota));
        }
        public IHttpActionResult PutSector(int id, Sector sector)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != sector.Id)
            {
                return(BadRequest());
            }

            db.Entry(sector).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SectorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #3
0
        public ActionResult Edit([Bind(Include = "Id,Cedula,Nombre,Apellido,Fecha_nac,Direccion,Telefono,Sexo,Foto,TiendaId,Correo")] UserViewModel userModel)
        {
            if (ModelState.IsValid)
            {
                var user            = db.Users.FirstOrDefault(x => x.Id == userModel.Id);
                var applicationUser = userModel.BindItem(user);
                applicationUser.EmailConfirmed  = true;
                db.Entry(applicationUser).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            userModel.LoadModel(db.Users.Find(userModel.Id));

            userModel.Ciudades = db.Ciudades.ToList();
            if (userModel.Tienda != null)
            {
                ViewBag.TiendaId = new SelectList(db.Tiendas.Where(x => x.CiudadId == userModel.Tienda.CiudadId), "Id", "Nombre", userModel.TiendaId);
            }
            else
            {
                ViewBag.TiendaId = new SelectList(new List <Tienda>(), "Id", "Codigo");
            }
            return(View(userModel));
        }
Exemple #4
0
 public ActionResult Edit([Bind(Include = "Id,Codigo,Nombre")] Raza raza)
 {
     if (ModelState.IsValid)
     {
         db.Entry(raza).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(raza));
 }
        /// <summary>
        /// Update Entity
        /// </summary>
        /// <param name="entity">Entity to update</param>
        public virtual void Update(TEntity entity)
        {
            DbEntityEntry DbEntityEntry = dbContext.Entry(entity);
            var           key           = this.GetPrimaryKey(DbEntityEntry);

            if (DbEntityEntry.State == EntityState.Detached)
            {
                TEntity currentEntity = this.FindById(key);
                if (currentEntity != null)
                {
                    DbEntityEntry AttachedEntry = dbContext.Entry(currentEntity);
                    AttachedEntry.CurrentValues.SetValues(entity);
                }
                else
                {
                    dbSet.Attach(entity);
                    DbEntityEntry.State = EntityState.Modified;
                }
            }
        }
 public ActionResult Edit([Bind(Include = "Id,Codigo,Nombre,Costo,TipoId")] Tarea tarea)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tarea).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.TipoId = new SelectList(db.TipoTareas, "Id", "Nombre", tarea.TipoId);
     return(View(tarea));
 }
Exemple #7
0
 public ActionResult Edit([Bind(Include = "Id,Codigo,Nombre,CiudadId")] Tienda tienda)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tienda).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CiudadId = new SelectList(db.Ciudades, "Id", "Nombre", tienda.CiudadId);
     return(View(tienda));
 }
 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));
 }
Exemple #9
0
 public HttpResponseMessage Put(int id, [FromBody] Tasks value)
 {
     try
     {
         value.Id = id;
         db.Entry(value).State = EntityState.Modified;
         return(ToJson(db.SaveChanges()));
     }
     catch (DbEntityValidationException ex)
     {
         return(JsonError("Datos de entrada invalidos"));
     }
 }