public virtual void Delete(T entity) { try { if (entity == null) { throw new ArgumentNullException("entity"); } if (_context.Entry(entity).State == EntityState.Detached) { DbSet.Attach(entity); } this.DbSet.Remove(entity); this._context.SaveChanges(); } catch (DbEntityValidationException dbEx) { var fail = GenerateException(dbEx); //Debug.WriteLine(fail.Message, fail); throw fail; } }
// Salva ou atualiza um objeto public void SalvarMedico(Medico medico) { try { // marca os attributos que são objetos como já existentes evitando a duplicação ctx.Entry(medico.Banco).State = System.Data.Entity.EntityState.Unchanged; ctx.Entry(medico.AreaAtuacao).State = System.Data.Entity.EntityState.Unchanged; if (medico.Id == 0) { ctx.Medicos.Add(medico); } else { var tempMedico = ctx.Medicos.SingleOrDefault(m => m.Id == medico.Id); tempMedico.Id = medico.Id; tempMedico.Crm = medico.Crm; tempMedico.Nome = medico.Nome; tempMedico.Cpf = medico.Cpf; tempMedico.Telefone = medico.Telefone; tempMedico.DataNasc = medico.DataNasc; tempMedico.Turno = medico.Turno; tempMedico.Banco = medico.Banco; tempMedico.AreaAtuacao = medico.AreaAtuacao; } ctx.SaveChanges(); } catch (Exception ex) { Util.HandleSQLDBException(ex); } }
public ActionResult Edit(FAQ faq) { try { if (ModelState.IsValid) { db.Entry(faq).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Purpose = db.Purposes.ToList(); return(View(faq)); } catch (DbUpdateException uex) { ViewBag.DbExceptionMessage = ErrorHandler.DbUpdateHandler(uex); //ViewBag.DbExceptionMessage = uex.Message; } catch (SqlException sqlException) { ViewBag.SqlExceptionMessage = sqlException.Message; } catch (Exception genericException) { ViewBag.ExceptionMessage = genericException.Message; } return(View("~/Views/Errors/Details.cshtml")); }
public ActionResult EditDisplay([Bind(Include = "ID,LastName,FirstName,DateOfBirth")] Patient patient) { if (ModelState.IsValid) { db.Entry(patient).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Display")); } return(View(patient)); }
// Salva ou atualiza um objeto public void SalvarObjeto(Consulta objeto) { try { // marca os attributos que são objetos como já existentes evitando a duplicação ctx.Entry(objeto.Paciente).State = System.Data.Entity.EntityState.Unchanged; ctx.Entry(objeto.Paciente.Convenio).State = System.Data.Entity.EntityState.Unchanged; //---------- // Objetos (class) que possuem mais de um objeto (class) aninhado // e melhor buscar pelo ctx do que marcar como nao alterado //---------- // seleciona um medico ja existente para atribuir ao objeto // evitando a duplicação do registro var medicoQuery = from medico in ctx.Medicos.Include("Banco").Include("AreaAtuacao") where medico.Id == objeto.Medico.Id select medico; objeto.Medico = medicoQuery.ToList().ElementAt(0); // seleciona um agendamento ja existente para atribuir ao objeto // evitando a duplicação do registro var agendamentoQuery = from agendamento in ctx.Agendamentos.Include("Paciente").Include("Medico").Include("Secretaria") where agendamento.Id == objeto.Agendamento.Id select agendamento; objeto.Agendamento = agendamentoQuery.ToList().ElementAt(0); if (objeto.Id == 0) { ctx.Consultas.Add(objeto); } else { var tempObjeto = ctx.Consultas.SingleOrDefault(temp => temp.Id == objeto.Id); tempObjeto.Id = objeto.Id; tempObjeto.Paciente = objeto.Paciente; tempObjeto.Medico = objeto.Medico; tempObjeto.Agendamento = objeto.Agendamento; tempObjeto.Data = objeto.Data; tempObjeto.PrecoTotal = objeto.PrecoTotal; } ctx.SaveChanges(); } catch (Exception ex) { Util.HandleSQLDBException(ex); } }
private static ForeignDoctor CreateOrUpdateDoctor(DPDoctor doctor) { var foreignDoctor = CheckDoctorContext(doctor.Id); foreignDoctor.Id = doctor.Id; foreignDoctor.Name = doctor.Name; foreignDoctor.Surname = doctor.Surname; if (db.Entry(foreignDoctor).State == EntityState.Detached) { db.ForeignDoctors.Add(foreignDoctor); } return(foreignDoctor); }
public ActionResult Edit(HttpPostedFileBase file, [Bind(Include = "Id,Title,Content,Slug,PostDate,UpdatedAt,PostStatus,AuthorId")] BlogPost blogPost) { if (ModelState.IsValid) { blogPost.UpdatedAt = DateTime.Now; // NOTE(batuhan): Retarded EF blogPost.PostDate = blogPost.PostDate; if (blogPost.Excerpt != _dbEntities.BlogPosts.Single(b => b.Id == blogPost.Id).Excerpt) { blogPost.Excerpt = ProcessContent(blogPost.Content); } if (file != null) { imageUploadHandler(file, blogPost); } _dbEntities.Entry(blogPost).State = EntityState.Modified; _dbEntities.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AuthorId = new SelectList(_dbEntities.HosMembers, "Id", "username", blogPost.AuthorId); ViewBag.PostStatus = new SelectList(new List <string> { "Publish", "Draft", "Revision" }, "Publish"); return(View("Admin/Edit", blogPost)); }
public IHttpActionResult PutBooking(int id, Booking booking) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != booking.BookingID) { return(BadRequest()); } db.Entry(booking).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookingExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutAssistant(int id, Assistant assistant) { if (id != assistant.AssistantId) { return(BadRequest()); } _context.Entry(assistant).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AssistantExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutDose([FromRoute] int id, [FromBody] Dose dose) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dose.ID) { return(BadRequest()); } _context.Entry(dose).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DoseExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PutNurse(int id, Nurse nurse) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != nurse.NurseID) { return(BadRequest()); } db.Entry(nurse).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!NurseExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit_Admin([Bind(Include = "Id,Subject,Content")] TestimonialVM testimonial) { try { //testimonial.Reviewed = "YES"; var dbTestimonial = db.Testimonials.Find(testimonial.Id); dbTestimonial.Subject = testimonial.Subject; dbTestimonial.Content = testimonial.Content; dbTestimonial.Reviewed = "YES"; if (ModelState.IsValid) { db.Entry(dbTestimonial).State = EntityState.Modified; db.SaveChanges(); TempData["SuccessMessage"] = "The testimonial has been successfully posted."; return(RedirectToAction("Index_Admin")); } ViewBag.departments = db.departments.ToList(); return(View(testimonial)); } catch (DbUpdateException dbException) { ViewBag.DbExceptionMessage = dbException.Message; } catch (SqlException sqlException) { ViewBag.SqlException = sqlException.Message; } catch (Exception genericException) { ViewBag.ExceptionMessage = genericException.Message; } return(View("~/Views/Errors/Details.cshtml")); }
public async Task <IActionResult> PutMedicin(int id, Medicin medicin) { if (id != medicin.MedicinId) { return(BadRequest()); } _context.Entry(medicin).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MedicinExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult Edit(Department d) { var department = _db.Department.Find(d.Id); if (department != null) { department.Id = d.Id; department.Name = d.Name; department.Details = d.Details; } if (ModelState.IsValid) { try { _db.Entry(department).State = Microsoft.EntityFrameworkCore.EntityState.Modified; if (_db.SaveChanges() > 0) { TempData["Result"] = "Record Update Successfully."; } else { TempData["Result"] = "Record Update Failed"; } } catch (Exception ex) { TempData["Result"] = ex.Message.ToString(); } } else if (!ModelState.IsValid) { return(View()); } return(RedirectToAction("Index")); }
public ActionResult Editar(Especialidade especialidade) { _context.Entry(especialidade).State = EntityState.Modified; _context.SaveChanges(); TempData["msg"] = "Atualizado com sucesso"; return(RedirectToAction("Listar")); }
public async Task <IActionResult> PutHospital([FromRoute] int id, [FromBody] Hospital hospital) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != hospital.Id) { return(BadRequest()); } _context.Entry(hospital).State = EntityState.Modified; try { _repo.Update(hospital); var save = await _repo.SaveAsync(hospital); } catch (DbUpdateConcurrencyException) { if (!HospitalExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutPriscriptions(int id, Priscriptions priscriptions) { if (id != priscriptions.PriscriptionId) { return(BadRequest()); } _context.Entry(priscriptions).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PriscriptionsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PutDoctor(int id, Doctor doctor) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != doctor.DoctorID) { return(BadRequest()); } db.Entry(doctor).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DoctorExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public PartialViewResult GetCurrentTime() { CalculateNewERTime(); var erWaitTime = _db.ERWaitTimes.First(x => x.Lock == "X"); if (erWaitTime.UpdatedAt.AddHours(1) < DateTime.Now) { erWaitTime.UpdatedAt = DateTime.Now; erWaitTime.CurrentWaitTime = 0; // TODO(batuhan): Save to archive. _db.Entry(erWaitTime).State = EntityState.Modified; _db.SaveChanges(); } return(PartialView("_ERWaitTimes", erWaitTime)); }
public ActionResult Edit([Bind(Include = "Id,UserName,DateOfSurvey,QualityService,AverageVisit,AppointmentIssue,StaffRate,Comment")] Survey survey) { try { if (ModelState.IsValid) { db.Entry(survey).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(survey)); } catch (DbUpdateException uex) { ViewBag.DbExceptionMessage = ErrorHandler.DbUpdateHandler(uex); //ViewBag.DbExceptionMessage = uex.Message; } catch (SqlException sqlException) { ViewBag.SqlExceptionMessage = sqlException.Message; } catch (Exception Exception) { TempData["ExceptionMessage"] = Exception.Message; } return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,VisitorEmail,VisitorName,Date,Question,Reply")] contactu contactu) { if (ModelState.IsValid) { db.Entry(contactu).State = EntityState.Modified; db.SaveChanges(); //if SMTP was setup, it will send a mail //MailMessage mail = new MailMessage(); // mail.To.Add(contactu.VisitorEmail); //mail.From = new MailAddress("*****@*****.**"); //mail.Subject = "Muskoka Hospital Reply to your Question"; //string Body = contactu.Reply; //mail.Body = Body; //mail.IsBodyHtml = true; //SmtpClient smtp = new SmtpClient(); //smtp.Host = "smtp.gmail.com"; //smtp.Port = 587; //smtp.UseDefaultCredentials = false; //smtp.Credentials = new System.Net.NetworkCredential //("username", "password");// Sender's usrname and password goes here //smtp.EnableSsl = true; //smtp.Send(mail); return(RedirectToAction("Index")); } return(View(contactu)); }
public ActionResult Edit([Bind(Include = "JobId,JobTitle,JobStatus,JobDescription,DepartmentId,DatePosted,DateClosed,JobShift,Salary,Requirement,UserId")] Job job) { try { if (ModelState.IsValid) { db.Entry(job).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index_Admin")); } ViewBag.departments = db.departments.ToList(); ViewBag.users = db.Users.ToList(); return(View(job)); } catch (DbUpdateException dbException) { ViewBag.DbExceptionMessage = dbException.Message; } catch (SqlException sqlException) { ViewBag.SqlException = sqlException.Message; } catch (Exception genericException) { ViewBag.ExceptionMessage = genericException.Message; } return(View("~/Views/Errors/General.cshtml")); }
// Salva ou atualiza um objeto public void SalvarObjeto(Secretaria objeto) { try { // marca os attributos que são objetos como já existentes evitando a duplicação ctx.Entry(objeto.Banco).State = System.Data.Entity.EntityState.Unchanged; if (objeto.Id == 0) { ctx.Secretarias.Add(objeto); } else { var tempObjeto = ctx.Secretarias.SingleOrDefault(temp => temp.Id == objeto.Id); tempObjeto.Id = objeto.Id; tempObjeto.Nome = objeto.Nome; tempObjeto.Cpf = objeto.Cpf; tempObjeto.DataNasc = objeto.DataNasc; tempObjeto.Telefone = objeto.Telefone; tempObjeto.Banco = objeto.Banco; } ctx.SaveChanges(); } catch (Exception ex) { Util.HandleSQLDBException(ex); } }
public ActionResult Update(Doctor doctor) { try { ViewBag.Departments = db.departments.ToList(); Doctor olddoctor = db.Doctors.FirstOrDefault(e => e.Doctorid == doctor.Doctorid); if (ModelState.IsValid) { ViewBag.err = "invalid"; db.Entry(olddoctor).CurrentValues.SetValues(doctor); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); } catch (DbUpdateException d) { ViewBag.DbExceptionMessage = ErrorHandler.DbUpdateHandler(d); //ViewBag.DbExceptionMessage = uex.Message; } catch (SqlException sq) { ViewBag.SqlExceptionMessage = sq.Message; } catch (Exception e) { ViewBag.ExceptionMessage = e.Message; } return(View("~/Views/Errors/Details.cshtml")); }
public async Task <IActionResult> PutDepartments(int id, Departments departments) { if (id != departments.DepartmentId) { return(BadRequest()); } _context.Entry(departments).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
// PUT api/values/5 public void EditBook(string fullname, [FromBody] Pacients pacients) { if (fullname == pacients.fullname) { db.Entry(pacients).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
public ActionResult Create([Bind(Include = "Id,dr_id,First_Name,Last_Name,Email_id,contact_no,avail_id,Date ")] book_an_appointment book_an_appointment) { if (ModelState.IsValid) { db.book_an_appointment.Add(book_an_appointment); db.SaveChanges(); DoctorAvailability doctorAvailability = db.DoctorAvailabilities.Find(book_an_appointment.avail_id); doctorAvailability.status = "Book"; db.Entry(doctorAvailability).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("SuccessMessage")); } ViewBag.dr_id = new SelectList(db.doctors, "Id", "Name", book_an_appointment.dr_id); ViewBag.avail_id = new SelectList(db.DoctorAvailabilities, "Id", "time", book_an_appointment.avail_id); return(View(book_an_appointment)); }
public void createPaciente(Paciente Paciente) { Paciente tempPaciente = new Paciente(); tempPaciente.Nome = Paciente.Nome; tempPaciente.Nascimento = Paciente.Nascimento; tempPaciente.Telefone = Paciente.Telefone; tempPaciente.CPF = Paciente.CPF; tempPaciente.Convenio = Paciente.Convenio; if (tempPaciente.Convenio != null) { ctx.Entry(tempPaciente.Convenio).State = System.Data.Entity.EntityState.Unchanged; } ctx.Pacientes.Add(tempPaciente); ctx.SaveChanges(); }
public ActionResult Edit([Bind(Include = "ID,Name,City,State")] Hospital hospital) { if (ModelState.IsValid) { db.Entry(hospital).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hospital)); }
public ActionResult Edit([Bind(Include = "WardTypeId,Name,description")] WardType wardType) { if (ModelState.IsValid) { db.Entry(wardType).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(wardType)); }