public async Task <IActionResult> PutTreatment(int id, Treatment treatment) { if (id != treatment.TreatmentId) { return(BadRequest()); } _context.Entry(treatment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TreatmentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Patient> > PutPatient(int id, Patient patient) { if (id != patient.PatientId) { return(BadRequest()); } _context.Entry(patient).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PatientExists(id)) { return(NotFound()); } else { throw; } } var result = await _context.Patients.FindAsync(id); return(result); }
public async Task <IActionResult> PutTreatmentType(int id, TreatmentType treatmentType) { if (id != treatmentType.TreatmentTypeId) { return(BadRequest()); } _context.Entry(treatmentType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TreatmentTypeExists(id)) { return(NotFound()); } else { throw; } } return(CreatedAtAction("GetTreatmentType", new { id = treatmentType.TreatmentTypeId }, treatmentType)); }
public Patient Insert(Patient p) { BeginTransaction(); try { context.Database.UseTransaction(Transaction as System.Data.Common.DbTransaction); dapper.Transaction = Transaction; //context.Patients.Attach(p); context.Entry <Patient>(p).State = EntityState.Added; context.Patients.Add(p); context.SaveChanges(); p.Address = "Updated Address Dpr"; dapper.Update(p); Transaction.Commit(); } catch (Exception ex) { Transaction.Rollback(); } return(p); }
public async Task PatientRepositroyUpdatePatientAsyncSuccessTest() { var testModel = new PatientModel() { Id = new Guid(), FirstName = "John", LastName = "Hu", Gender = Gender.male, DateOfBirth = new DateTime(1992, 2, 14), Email = "*****@*****.**", Phone = "0425789632", CreateTime = DateTime.Now, UpdateTime = DateTime.Now, }; var expected = new PatientModel() { Id = testModel.Id, FirstName = "Tee", LastName = "Hu", Gender = Gender.male, DateOfBirth = new DateTime(1992, 2, 14), Email = "*****@*****.**", Phone = "0425789632", CreateTime = DateTime.Now, UpdateTime = DateTime.Now, }; using (var context = new PatientDbContext(dbOptionsBuilder.Options)) { context.Patients.Add(testModel); context.SaveChanges(); var entity = context.Patients.Single(p => p.Id == testModel.Id); //To Avoid tracking error context.Entry(entity).State = EntityState.Detached; var repo = new PatientRepository(context); var result = await repo.UpdatePatientAsync( new PatientModel() { Id = testModel.Id, FirstName = "Tee", LastName = "Hu", Gender = Gender.male, DateOfBirth = new DateTime(1992, 2, 14), Email = "*****@*****.**", Phone = "0425789632", CreateTime = DateTime.Now, UpdateTime = DateTime.Now, }); context.SaveChanges(); Assert.AreEqual("Tee", result.FirstName); } }
public async Task <ActionResult <TreatmentViewModel> > PutTreatment(int id, Treatment treatment) { if (id != treatment.TreatmentId) { System.Console.WriteLine("Hello from Error"); return(BadRequest()); } _context.Entry(treatment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TreatmentExists(id)) { return(NotFound()); } else { throw; } } var treatmentType = await _context.TreatmentTypes.FindAsync(treatment.TreatmentTypeId); var t = await _context.Treatments.FindAsync(id); var result = new TreatmentViewModel() { TreatmentId = t.TreatmentId, UserId = t.UserId, TreatmentCost = t.TreatmentCost, CreatedAt = t.CreatedAt, TreatmentImageUrl = t.TreatmentImageUrl, TreatmentImageName = t.TreatmentImageName, PatientId = t.PatientId, TreatmentName = treatmentType.Name, TreatmentTypeId = t.TreatmentTypeId }; return(result); }
public async Task <TreatmentViewModel> Update(int id, Treatment treatment) { _context.Entry(treatment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TreatmentExists(id)) { return(null); } else { throw; } } var treatmentType = await _context.TreatmentTypes.FindAsync(treatment.TreatmentTypeId); var t = await _context.Treatments.Where(t => t.UserId.Contains(treatment.UserId) && t.TreatmentId.Equals(id)).FirstAsync(); var result = new TreatmentViewModel() { TreatmentId = t.TreatmentId, UserId = t.UserId, TreatmentCost = t.TreatmentCost, CreatedAt = t.CreatedAt, TreatmentImageUrl = t.TreatmentImageUrl, TreatmentImageName = t.TreatmentImageName, PatientId = t.PatientId, TreatmentName = treatmentType.Name, TreatmentTypeId = t.TreatmentTypeId }; return(result); }
public async Task <TreatmentType> Update(int id, TreatmentType treatmentType) { _context.Entry(treatmentType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TreatmentTypeExists(id)) { return(null); } else { throw; } } return(treatmentType); }
public async Task <Patient> Update(int id, Patient patient) { _context.Entry(patient).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PatientExists(id)) { return(null); } else { throw; } } var result = await _context.Patients.FindAsync(id); return(result); }