public async Task <IActionResult> PutStudent([FromRoute] int id, [FromBody] Student student)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
示例#2
0
        public async Task <Response> Create(Owner item)
        {
            try
            {
                item.User = null;
                await _context.Owners.AddAsync(item);

                await _context.SaveChangesAsync();

                return(new Response()
                {
                    Success = true
                });
            }
            catch (Exception e)
            {
                Response r = new Response()
                {
                    Success = false
                };

                if (e.InnerException.Message.Contains("unique index"))
                {
                    r.ErrorList.Add("Owner already exists");
                }
                else
                {
                    r.ErrorList.Add("Insert owner error");
                }
                StringBuilder sb = new StringBuilder();
                log.Error(sb.AppendLine(e.Message).AppendLine(e.StackTrace).ToString());
                return(r);
            }
        }
示例#3
0
        public async Task <Response> Create(Class item)
        {
            Response response = new Response();

            try
            {
                item.Subject = null;
                item.Course  = null;

                item.CreatedAt = DateTime.Now;
                await _context.Classes.AddAsync(item);

                await _context.SaveChangesAsync();

                return(response);
            }
            catch (Exception e)
            {
                response.Success = false;
                response.ErrorList.Add("Error while adding Class.");
                StringBuilder sb = new StringBuilder();
                log.Error(sb.AppendLine(e.Message).AppendLine(e.StackTrace).ToString());
                return(response);
            }
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("AñoCreacion,Pais,Ciudad,TipoEscuela,Direccion,Nombre,Id")] Academy academy)
        {
            if (ModelState.IsValid)
            {
                _context.Add(academy);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(academy));
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("FechaDeLanzamiento,CursoId,Nombre,Id")] Asignatura asignatura)
        {
            if (ModelState.IsValid)
            {
                _context.Add(asignatura);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CursoId"] = new SelectList(_context.Cursos, "Id", "Id", asignatura.CursoId);
            return(View(asignatura));
        }
示例#6
0
        public async Task <IActionResult> Create([Bind("Nombre,Jornada,Direccion,AcademyId,Id")] Curso curso)
        {
            if (ModelState.IsValid)
            {
                _context.Add(curso);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AcademyId"] = new SelectList(_context.Academies, "Id", "Id", curso.AcademyId);
            return(View(curso));
        }
示例#7
0
        public async Task <IActionResult> Create([Bind("CursoId,Nombre,Id")] Alumno alumno)
        {
            if (ModelState.IsValid)
            {
                _context.Add(alumno);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CursoId"] = new SelectList(_context.Cursos, "Id", "Id", alumno.CursoId);
            return(View(alumno));
        }
示例#8
0
        public async Task <Response> Create(Course item)
        {
            Response response = new Response();

            try
            {
                item.CreatedAt = DateTime.Now;
                await _context.Courses.AddAsync(item);

                await _context.SaveChangesAsync();

                return(response);
            }
            catch (Exception e)
            {
                response.Success = false;
                if (e.Message.Contains("Name"))
                {
                    response.ErrorList.Add("Name is required.");
                }
                if (e.Message.Contains("Period"))
                {
                    response.ErrorList.Add("Period is required.");
                }
                else
                {
                    response.ErrorList.Add("Error while adding Course.");
                }

                StringBuilder sb = new StringBuilder();
                log.Error(sb.AppendLine(e.Message).AppendLine(e.StackTrace).ToString());
                return(response);
            }
        }
示例#9
0
        public async Task <Response> AddCoordinator(User user, Coordinator coordinator)
        {
            Response r = new Response();

            try
            {
                (await _context.Users.Include(c => c.Coordinator).Where(c => c.ID == user.ID).FirstOrDefaultAsync()).Coordinator = coordinator;
                await _context.SaveChangesAsync();

                return(r);
            }
            catch (Exception e)
            {
                StringBuilder sb = new StringBuilder();
                log.Error(sb.AppendLine(e.Message).AppendLine(e.StackTrace).ToString());
                r.Success = false;
                r.ErrorList.Add("Error on add coordinator to user");
                return(r);
            }
        }