public async Task <ActionResult> PostExam([FromBody] ExamAddViewModel exam) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Exam examToPost = new Exam(); examToPost.ExamId = exam.ExamId; examToPost.ExamDate = exam.ExamDate; examToPost.ExamCode = exam.ExamCode; examToPost.FullMark = exam.FullMark; examToPost.PassMark = exam.PassMark; examToPost.SessionId = exam.SessionId; _repo.Add(examToPost); var save = await _repo.SaveAsync(examToPost); foreach (var item in exam.Subjects) { ExamSubject es = new ExamSubject(); es.ExamId = save.ExamId; es.SubjectId = item.SubjectId; es.Mark = item.Mark; es.PassMark = item.PassMark; _esRepo.Add(es); var esp = await _esRepo.SaveAsync(es); examToPost.Subjects.Add(es); } return(Ok()); }
public async Task <ActionResult> PostSubject([FromBody] Subject subject) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _repo.Add(subject); var save = await _repo.SaveAsync(subject); return(CreatedAtAction("GetSubjects", new { id = subject.SubjectId }, subject)); }
public async Task <ActionResult> PostCenter([FromBody] ExamCenter center) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _repo.Add(center); var save = await _repo.SaveAsync(center); return(CreatedAtAction("GetCenter", new { id = center.CenterId }, center)); }
public async Task <ActionResult> PostStandard([FromBody] StanderdClass standard) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _repo.Add(standard); var save = await _repo.SaveAsync(standard); return(CreatedAtAction("GetStandard", new { id = standard.ClassId }, standard)); }
public async Task <ActionResult> PostRoom([FromBody] Room room) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _repo.Add(room); var save = await _repo.SaveAsync(room); return(CreatedAtAction("GetRoom", new { id = room.RoomId }, room)); }
public async Task <ActionResult> Post([FromBody] Session session) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _repo.Add(session); await _repo.SaveAsync(session); return(CreatedAtAction("GetById", new { id = session.SessionId }, session)); }
public async Task <ActionResult> PostNotice([FromBody] Notice notice) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _repo.Add(notice); var save = await _repo.SaveAsync(notice); return(CreatedAtAction("GetNotices", new { id = notice.NoticeID }, notice)); }
public async Task <ActionResult> PostCandidate([FromForm] CandidateAddViewModel candidate) { var a = candidate; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (candidate.ExamId > 0) { if (candidate.TC != null && candidate.Image != null) { string NewImageName = Guid.NewGuid().ToString() + "_" + candidate.Image.FileName; string NewImagePath = Path.Combine("Images", NewImageName); string image = Path.Combine(_hostEnv.WebRootPath, NewImagePath); candidate.Image.CopyTo(new FileStream(image, FileMode.Create)); string NewFileName = Guid.NewGuid().ToString() + "_" + candidate.TC.FileName; string NewFilePath = Path.Combine("Files", NewFileName); string file = Path.Combine(_hostEnv.WebRootPath, NewFilePath); candidate.Image.CopyTo(new FileStream(file, FileMode.Create)); Candidate candidateToPost = _mapper.Map <Candidate>(candidate); candidateToPost.ImagePath = NewImagePath; candidateToPost.TCPath = NewFilePath; _repo.Add(candidateToPost); var save = await _repo.SaveAsync(candidateToPost); var rooms = await _room.GetT(); foreach (var room in rooms) { if (_roomCandidateRepo.CountCandidatesInRoom(room.RoomId, candidate.ExamId) < room.Capacity) { RoomCandidate rc = new RoomCandidate { RoomId = room.RoomId, ExamId = candidate.ExamId, CandidateId = candidateToPost.CandidateId }; _seat.Add(rc); await _seat.SaveAsync(rc); candidateToPost.Exams = null; rc.Room.RoomCandidates = null; return(Ok(rc)); } } return(Ok(candidateToPost)); } } return(BadRequest()); }