public async Task <IActionResult> PostEmployeeExam([FromBody] EmployeeExam employeeExam) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var firstCert = await _context.Certificates.FirstAsync(); var cert = await _context.Certificates.FindAsync(employeeExam.CertificateId); var query = from b in _context.EmployeeExams from p in _context.EmployeeCertificates.Where(p => b.CertificateId == p.CertificateId) from c in _context.Certificates.Where(c => p.CertificateId == c.CertificateId).Where(a => b.EmployeeId == employeeExam.EmployeeId) select new { b, p, c }; if (cert.Title == "ISTQB Advanced Level") { var query1 = query.Select(s => s.c).Where(a => a.Title == "ISTQB Foundation Level"); if (query1.Count() == 0) { return(BadRequest("Negalite registruotis, nes nelaikėte " + firstCert.Title + " egzamino.")); } } if (cert.Title == "ISTQB Expert Level") { var query1 = query.Select(s => s.c).Where(a => a.Title == "ISTQB Advanced Level"); if (query1.Count() == 0) { return(BadRequest("Negalite registruotis, nes neturite ISTQB Advanced Level sertifikato.")); } } if (employeeExam.Price <= 0) { return(BadRequest("Kaina turi būti didesnė už 0")); } employeeExam.PlannedExamDate = employeeExam.PlannedExamDate.ToLocalTime(); employeeExam.RealExamDate = employeeExam.RealExamDate?.ToLocalTime(); if (employeeExam.IsPassed == true) { employeeExam.File = GetFile(); } else { employeeExam.File = "NULL"; } _context.EmployeeExams.Add(employeeExam); await _context.SaveChangesAsync(); return(CreatedAtAction("GetEmployeeExam", new { id = employeeExam.EmployeeExamId }, employeeExam)); }
public async Task <IActionResult> PutEmployeeExam([FromRoute] int id, [FromBody] EmployeeExam employeeExam) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employeeExam.EmployeeExamId) { return(BadRequest()); } if (employeeExam.Price <= 0) { return(BadRequest("Kaina turi būti didesnė už 0")); } employeeExam.PlannedExamDate = employeeExam.PlannedExamDate.ToLocalTime(); employeeExam.RealExamDate = employeeExam.RealExamDate?.ToLocalTime(); if (employeeExam.IsPassed == true) { employeeExam.File = GetFile(); } else { employeeExam.File = "NULL"; } _context.Entry(employeeExam).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExamExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }