Ejemplo n.º 1
0
        public async Task <IActionResult> PutUsers([FromRoute] int id, [FromBody] Users users)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutSchedules([FromRoute] int id, [FromBody] Schedules schedules)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            var scheduleExist = _context.Schedules
                                .Where(s => s.DoctorId == schedules.DoctorId &&
                                       s.PatientId != schedules.PatientId &&
                                       s.Date == schedules.Date)
                                .SingleOrDefault();

            if (scheduleExist == null && schedules.Date >= DateTime.Now)
            {
                _context.Entry(schedules).State = EntityState.Modified;

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

                return(NoContent());
            }

            return(BadRequest("Horário indisponível nesta data!"));
        }