Пример #1
0
        public bool Update(Student student)
        {
            int isExecuted = 0;

            db.Entry(student).State = EntityState.Modified;
            isExecuted = db.SaveChanges();
            if (isExecuted > 0)
            {
                return(true);
            }
            return(false);
        }
Пример #2
0
        public string UpdateDoctors(DoctorRequest request)
        {
            var update_doctor = new Doctor
            {
                Id        = request.IdDoctor,
                FirstName = request.FirstName,
                LastName  = request.LastName,
                Email     = request.Email
            };

            _context.Update(update_doctor);
            try
            {
                _context.Entry(update_doctor).State = EntityState.Modified;
                _context.SaveChanges();
            }
            catch (Exception)
            {
                return(null);
            }
            return("A doctor has been successfully updated");
        }
        public async Task <ActionResult <ApiResponse <Post> > > PutPost(int id, Post post)
        {
            var result = new ApiResponse <Post>(1, null, false, null);

            if (id != post.Id)
            {
                result.ResultCode   = 0;
                result.ErrorDisplay = true;
                result.ErrorMessage = "Bad request!";
                return(result);
            }

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

            try
            {
                await _context.SaveChangesAsync();

                result.ResultData = post;
            }
            catch (DbUpdateConcurrencyException dbx)
            {
                if (!PostExists(id))
                {
                    result.ResultCode   = 0;
                    result.ErrorDisplay = true;
                    result.ErrorMessage = "Not Found!";
                    return(result);
                }
                else
                {
                    _logger.LogError("DbUpdateConcurrencyException", dbx);
                    result.ResultCode   = 0;
                    result.ErrorDisplay = true;
                    result.ErrorMessage = "Bad request!";
                    return(result);
                }
            }

            return(result);
        }
 public virtual void Update(TEntity entity)
 {
     entity.Date = DateTime.UtcNow;
     DbContext.Entry(entity).State = EntityState.Modified;
     DbContext.SaveChanges();
 }