public async Task <ActionResult <DCandidate> > PostDCandidate(DCandidate dCandidate) { _context.DCandidates.Add(dCandidate); await _context.SaveChangesAsync(); return(CreatedAtAction("GetDCandidate", new { id = dCandidate.id }, dCandidate)); }
public async Task <IActionResult> PutDCandidate(int id, DCandidate dCandidate) { //if (id != dCandidate.id) //{ // return BadRequest(); //} dCandidate.id = id; _context.Entry(dCandidate).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DCandidateExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public JsonResult Post(DCandidate cous) { string query = @" insert into dbo.Dcandidate (DCandidateId,UserName,Email,Password,ConfrimPassword,Address) values ( '" + cous.DCandidateId + @"' ,'" + cous.UserName + @"' ,'" + cous.Email + @"' ,'" + cous.Password + @"' ,'" + cous.ConfrimPassword + @"' ,'" + cous.Address + @"' ) "; DataTable table = new DataTable(); string sqlDataSource = _context.GetConnectionString("DcandisateAppCon"); SqlDataReader myReader; using (SqlConnection myCon = new SqlConnection(sqlDataSource)) { myCon.Open(); using SqlCommand myCommand = new SqlCommand(query, myCon); myReader = myCommand.ExecuteReader(); table.Load(myReader);; myReader.Close(); myCon.Close(); } return(new JsonResult("Added Successfully")); }
public async Task <IActionResult> PutDCandidate(int id, [FromForm] DCandidate dCandidate) { dCandidate.EmployeeID = id; _context.Entry(dCandidate).State = EntityState.Modified; if (id != dCandidate.EmployeeID) { return(BadRequest()); } if (dCandidate.ImageFile != null) { DeleteImage(dCandidate.ImageName); dCandidate.ImageName = await SaveImage(dCandidate.ImageFile); } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DCandidateExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutDCandidate([FromRoute] int id, [FromBody] DCandidate dCandidate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dCandidate.id) { return(BadRequest()); } _context.Entry(dCandidate).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DCandidateExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <DCandidate> > PostDCandidate([FromForm] DCandidate dCandidate) { dCandidate.ImageName = await SaveImage(dCandidate.ImageFile); _context.DCandidates.Add(dCandidate); await _context.SaveChangesAsync(); //return CreatedAtAction("GetDCandidate", new { id = dCandidate.EmployeeID }, dCandidate); return(StatusCode(201)); }
public async Task <IActionResult> PostDCandidate([FromBody] DCandidate dCandidate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.DCandidates.Add(dCandidate); await _context.SaveChangesAsync(); return(CreatedAtAction("GetDCandidate", new { id = dCandidate.id }, dCandidate)); }
public IActionResult Register([FromBody] DCandidate model) { // map model to entity var candidate = _mapper.Map <Candidate>(model); try { // create candidate _candidateService.Create(candidate); return(Ok()); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public IActionResult Update(int id, [FromBody] DCandidate model) { // map model to entity and set id var candidate = _mapper.Map <Candidate>(model); candidate.Id = id; try { // update candidate _candidateService.Update(candidate); return(Ok()); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public async Task <IActionResult> PutDCandidate(int id, DCandidate dCandidate) { //checked for stuff //if (id != dCandidate.Id) //{ // return BadRequest(); //} dCandidate.Id = id; //var dbCandidate = _context.DCandidates.Where(dc => dc.Id == id).FirstOrDefault(); //dbCandidate.Entity.Address = dCandidate.Address ?? dbCandidate.Entity.Address; //dbCandidate.Entity.FullName = dCandidate.FullName ?? dbCandidate.Entity.FullName; //dbCandidate.Entity.Email = dCandidate.Email ?? dbCandidate.Entity.Email; //dbCandidate.State = EntityState.Modified; _context.Entry(dCandidate).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DCandidateExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }