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