Ejemplo n.º 1
0
        public IActionResult Put(Category category)
        {
            using var context = new WebApiContext();
            //var response = context.Categories.Find(category.Id);
            var response = context.Find <Category>(category.Id);

            if (response == null)
            {
                return(NotFound());
            }

            response.Name = category.Name;
            context.Update(response);
            context.SaveChanges();
            return(NoContent());
        }
        public ActionResult AddSchedule([FromBody] Schedule schedule)
        {
            try
            {
                if (context.Find(typeof(Schedule), schedule.Id) != null)
                {
                    throw new Exception($"Schedule {schedule.Id} already exists");
                }

                context.Schedules.Add(schedule);
                context.SaveChanges();
                return(Ok());
            }
            catch (System.Exception ex)
            {
                return(BadRequest(ex.Message));

                throw;
            }
        }