Beispiel #1
0
        public ActionResult AddProfessional([FromBody] DoctorProfessionalView model)
        {
            try
            {
                foreach (int professId in model.ProfessionalId)
                {
                    if (_context.DoctorProfessional.Where(dp => dp.DoctorId == model.DoctorId && dp.ProfessionalId == professId).Count() == 0)
                    {
                        DoctorProfessional doctorProfessional = new DoctorProfessional {
                            DoctorId = model.DoctorId, ProfessionalId = professId
                        };
                        _context.DoctorProfessional.Add(doctorProfessional);
                    }
                    else
                    {
                        Console.WriteLine("The doctor already have this professional - exist: " + professId);
                    }
                }
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                return(Conflict());
            }

            var result = new
            {
                Meta = new { Status = "OK", Message = "Add Professioanl Successfully" }
            };

            return(Ok(result));
        }
 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));
     }
 }