public async Task <IActionResult> PutJournalist(long id, SubmitJour njournalist) { var isEditor = bool.Parse(_httpContextAccessor.HttpContext.Request.Headers["isEditor"]); if (!isEditor) { return(NotFound()); } var journalist = await GetAJournalist(id); if (journalist == null) { return(BadRequest()); } journalist.Entity.Password = njournalist.Password ?? journalist.Entity.Password; journalist.Entity.Name = njournalist.Journalist.Name ?? journalist.Entity.Name; journalist.Entity.Age = njournalist.Journalist.Age ?? journalist.Entity.Age; journalist.Entity.Gender = njournalist.Journalist.Gender; journalist.Entity.Phonenumber = njournalist.Journalist.Phonenumber ?? journalist.Entity.Phonenumber; journalist.Entity.EmailAddress = njournalist.Journalist.EmailAddress ?? journalist.Entity.EmailAddress; journalist.Entity.Address = njournalist.Journalist.Address ?? journalist.Entity.Address; journalist.Property(p => p.Password).IsModified = true; journalist.Property(p => p.Name).IsModified = true; journalist.Property(p => p.Age).IsModified = true; journalist.Property(p => p.Gender).IsModified = true; journalist.Property(p => p.Phonenumber).IsModified = true; journalist.Property(p => p.EmailAddress).IsModified = true; journalist.Property(p => p.Address).IsModified = true; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!JournalistExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Journalist> > PostJournalist(SubmitJour journalist) { var isEditor = bool.Parse(_httpContextAccessor.HttpContext.Request.Headers["isEditor"]); if (!isEditor) { return(NotFound()); } journalist.Journalist.Password = journalist.Password; _context.Journalists.Add(journalist.Journalist); await _context.SaveChangesAsync(); return(CreatedAtAction("GetJournalist", new { id = journalist.Journalist.JournalistId }, journalist.Journalist)); }