public async Task <IActionResult> PutDoctorActivate(int id, DoctorActivate doctorActivate)
        {
            if (id != doctorActivate.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <ActionResult <DoctorActivate> > PostDoctorActivate(DoctorActivate doctorActivate)
        {
            _context.DoctorActivate.Add(doctorActivate);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDoctorActivate", new { id = doctorActivate.Id }, doctorActivate));
        }
 public ActionResult DoctorActivateDeactivateSession(int doctorId, int state)
 {
     if (_context.DoctorActivate.Where(p => p.Activate == true & p.DoctorId == doctorId & p.EndTime == null).Count() >= 1 && state == 1)
     {
         var result = new { meta = "Ok", message = "Doctor is already activate" };
         return(Ok(result));
     }
     if (_context.Doctor.Find(doctorId) != null)
     {
         if (state == 1)
         {
             try
             {
                 var doctorActivate = new DoctorActivate {
                     Activate = true, DoctorId = doctorId
                 };
                 _context.DoctorActivate.Add(doctorActivate);
                 _context.SaveChanges();
             }
             catch (Exception e)
             {
                 return(BadRequest());
             }
             var result = new { status = "OK", message = "Doctor Activate Session" };
             return(Ok(result));
         }
         else
         {
             if (_context.DoctorActivate.Where(p => p.DoctorId == doctorId && p.Activate == true).Count() >= 1)
             {
                 var doctorDeactivate = _context.DoctorActivate.Where(p => p.DoctorId == doctorId && p.Activate == true).Single();
                 doctorDeactivate.Activate = false;
                 doctorDeactivate.EndTime  = DateTime.Now;
                 _context.Entry(doctorDeactivate).State = EntityState.Modified;
                 _context.SaveChanges();
                 var result = new { status = "OK", message = "Deactivate session successfully" };
                 return(Ok(result));
             }
             return(BadRequest());
         }
     }
     else
     {
         var result = new { status = "Bad", message = "Incorrect doctorID" };
         return(BadRequest(result));
     }
 }