public async Task <IActionResult> PutStudent(ulong id, Student student) { if (id != student.StudentId) { 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 <IActionResult> PutMachine(string id, Machine machine) { if (id != machine.name) { return(BadRequest()); } _context.Entry(machine).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MachineExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutCalendar(IFormFile file) { //file is a csv var reader = new StreamReader(file.OpenReadStream()); await reader.ReadLineAsync();//discard column names string v = ""; while ((v = await reader.ReadLineAsync()) != null) { v = v.Trim('"'); var split = v.Split("\",\"");//get signInDTO from each line string signInJSON = string.Format( "{{\"StartTime\":{0},\"EndTime\":{1}," + "\"StudentId\":{2},\"MachineName\":{4}}}", $"\"{split[0]}\"", $"\"{split[1]}\"", $"\"{split[3]}\"", $"\"{split[2]}\""); SignInDTO signInDto = JsonSerializer.Deserialize <SignInDTO>(signInJSON); //make SignIn from SignInDTO var machine = await _context.Machines.FindAsync(signInDto.Machine.Name); var student = await _context.Students.FindAsync(signInDto.StudentId.Value); if (machine == null || student == null) { return(NotFound()); } SignIn signIn = new SignIn(); signIn.Student = student; signIn.Machine = machine; signIn.StartTime = signInDto.StartTime; signIn.EndTime = signInDto.EndTime; //add current record to db _context.SignIns.Add(signIn); await _context.SaveChangesAsync(); } return(NoContent()); }
public async Task <IActionResult> PutSignIn(int id, SignIn signIn) { _context.Entry(signIn).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SignInExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }