コード例 #1
0
        public async Task <IActionResult> PutUsers(int id, Users users)
        {
            if (id != users.Id)
            {
                return(BadRequest());
            }

            _context.Entry(users).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                producer.Produce("PUT User event fired...");
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UsersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public CustomResponse Put(int id, [FromBody] Users user)
        {
            try
            {
                if (id != user.Id)
                {
                    return(new CustomResponse {
                        State = 400, Message = "Error en la solicitud, deben coincidir los ids"
                    });
                }

                using (var context = new UserManagementContext())
                {
                    context.Entry(user).State = EntityState.Modified;
                    context.Entry(user).Property(x => x.Password).IsModified = false;
                    context.SaveChanges();
                }

                return(new CustomResponse {
                    State = 200, Message = "Modificación exitosa"
                });
            }
            catch (Exception ex)
            {
                return(new CustomResponse {
                    State = 500, Message = ex.Message.ToString()
                });
            }
        }
コード例 #3
0
        public virtual TEntity Update(TEntity t, object key)
        {
            if (t == null)
            {
                return(null);
            }
            TEntity exist = Context.Set <TEntity>().Find(key);

            if (exist != null)
            {
                Context.Entry(exist).CurrentValues.SetValues(t);
                Context.SaveChanges();
            }
            return(exist);
        }
コード例 #4
0
        public IHttpActionResult PutPatient(int id, Patient patient)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != patient.PatientID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #5
0
        // PUT api/User/5
        public HttpResponseMessage PutUser(int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != user.Id)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
コード例 #6
0
        public IHttpActionResult PutMedecin(int id, Medecin medecin)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != medecin.MedecinID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #7
0
        public IHttpActionResult PutUser(int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.UserId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #8
0
        public async Task <IHttpActionResult> PutServices(int id, Services services)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != services.ServiceID)
            {
                return(BadRequest());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ServicesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #9
0
 public void Update(T entity)
 {
     _dbSet.Attach(entity);
     _context.Entry(entity).State = EntityState.Modified;
 }