public int DeleteAppointment(int id) { tblAppointment appointment = _db.tblAppointments.Where(u => u.Id == id).FirstOrDefault(); _db.tblAppointments.Remove(appointment); return(_db.SaveChanges()); }
public ActionResult Search(int?appointmentID, string clientPassword) { if (appointmentID == null) { return(View()); } tblAppointment tblAppointment = db.tblAppointments.Find(appointmentID); try { string salt = tblAppointment.tblClient.salt; if ((Crypto.VerifyHashedPassword(tblAppointment.tblClient.Password, clientPassword + salt)) || (Session["user"] != null)) { TempData["userInfo"] = tblAppointment.appointmentID; tblEmployee tblEmployee = db.tblEmployees.Find(tblAppointment.employeeID); tblHaircut tblHaircut = db.tblHaircuts.Find(tblAppointment.haircutID); ViewData["timeSlot"] = tblAppointment.tblTimeSlot.timeSlot; ViewData["employee"] = tblEmployee.FirstName + " " + tblEmployee.LastName; ViewData["haircut"] = tblHaircut.HaircutName; if ((tblAppointment == null) || (tblEmployee == null) || (tblHaircut == null)) { return(HttpNotFound()); } return(View(tblAppointment)); } } catch (Exception) { ViewBag.searchError = "No appointment could be found please try again later!"; } return(View()); }
public async Task <ActionResult> appointmentConfirmation(int?appointmentID) { if (appointmentID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblAppointment tblAppointment = await db.tblAppointments.FindAsync(appointmentID); tblEmployee tblEmployee = await db.tblEmployees.FindAsync(tblAppointment.employeeID); tblHaircut tblHaircut = await db.tblHaircuts.FindAsync(tblAppointment.haircutID); tblTimeSlot tblTimeSlot = await db.tblTimeSlots.FindAsync(tblAppointment.timeSlotID); ViewData["employee"] = tblEmployee.FirstName + " " + tblEmployee.LastName; ViewData["haircut"] = tblHaircut.HaircutName; ViewData["timeSlot"] = tblTimeSlot.timeSlot; if (TempData["userInfo"] != null) { TempData.Keep("userInfo"); } if (tblAppointment == null) { return(HttpNotFound()); } return(View(tblAppointment)); }
public void InsertTest() { int expected = 1; int actual = 0; Guid customerId = dc.tblCustomers.First().Id; Guid employeeId = dc.tblEmployees.First().Id; Guid serviceId = dc.tblServiceTypes.First().Id; tblAppointment newAppointment = new tblAppointment { Id = Guid.NewGuid(), CustomerId = customerId, EmployeeId = employeeId, ServiceId = serviceId, StartDateTime = DateTime.Now, EndDateTime = DateTime.Now.AddHours(4), Status = "Pending" }; dc.tblAppointments.Add(newAppointment); actual = dc.SaveChanges(); appointmentId = newAppointment.Id; Assert.AreEqual(expected, actual); }
public int DeleteAppointmentOnTheBasisOfDeletedDateTime(int id) { tblAppointment appointment = _db.tblAppointments.Where(u => u.DateTimeId == id).FirstOrDefault(); _db.tblAppointments.Remove(appointment); return(_db.SaveChanges()); }
public ActionResult DeleteConfirmed(string id) { tblAppointment tblAppointment = db.tblAppointments.Find(id); db.tblAppointments.Remove(tblAppointment); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult changeAppointment(int?appointmentID) { ViewBag.employeeName = new SelectList(db.tblEmployees, "employeeID", "FirstName"); //ViewBag.Title = "Make new appointment"; ViewBag.haircutList = new SelectList(db.tblHaircuts, "HaircutID", "HaircutName"); tblAppointment tblAppointment = db.tblAppointments.Find(appointmentID); return(View(tblAppointment)); }
public async static Task <int> Update(Appointment appointment, bool rollback = false) { try { int results = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblAppointment updateRow = dc.tblAppointments.FirstOrDefault(r => r.Id == appointment.Id); if (updateRow != null) { updateRow.CustomerId = appointment.CustomerId; updateRow.EmployeeId = appointment.EmployeeId; updateRow.StartDateTime = appointment.StartDateTime; updateRow.EndDateTime = appointment.EndDateTime; updateRow.ServiceId = appointment.ServiceId; updateRow.Status = appointment.Status; dc.tblAppointments.Update(updateRow); // Commit the changes and get the number of rows affected results = dc.SaveChanges(); if (appointment.Status == AppointmentStatus.Completed.ToString()) { GenerateInvoice(appointment); } if (rollback) { transaction.Rollback(); } } else { throw new Exception("Appointment was not found."); } } }); return(results); } catch (Exception) { throw; } }
public int UpdateAppointment(BOAppointmentDetails model) { tblAppointment appointment = _db.tblAppointments.Where(u => u.Id == model.Id).FirstOrDefault(); appointment.AppointmentFrom = model.AppointmentFrom; appointment.AppointmentTo = model.AppointmentTo; appointment.DateTimeId = model.DateTimeId; appointment.DepartmentId = model.DepartmentId; appointment.Details = model.Details; return(_db.SaveChanges()); }
public int CreateAppointment(BOAppointmentDetails model) { tblAppointment appointment = new tblAppointment(); appointment.DepartmentId = model.DepartmentId; appointment.AppointmentFrom = model.AppointmentFrom; appointment.AppointmentTo = model.AppointmentTo; appointment.DateTimeId = model.DateTimeId; appointment.Details = model.Details; _db.tblAppointments.Add(appointment); return(_db.SaveChanges()); }
public ActionResult Edit([Bind(Include = "Appointment_Id,Appointment_Date,Appointment_Time,Appointment_Type,Doctor_Code,Patient_Code,Appointment_Room,Appointment_Code,Status")] tblAppointment tblAppointment) { if (ModelState.IsValid) { db.Entry(tblAppointment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Doctor_Code = new SelectList(db.tblDoctors, "Doctor_Code", "Doctor_Name", tblAppointment.Doctor_Code); ViewBag.Patient_Code = new SelectList(db.tblPatients, "Patient_Code", "Patient_Name", tblAppointment.Patient_Code); return(View(tblAppointment)); }
public async static Task <int> Delete(Guid id, bool rollback = false) { try { int results = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { // Check if appointment is in progress or completed .... bool inuse = dc.tblAppointments.Any(a => a.Id == id && a.Status == "InProgress" || a.Status == "Complete"); if (inuse && rollback == false) { throw new Exception("This appointment is currently in progress or completed and therefore cannot be deleted."); } else { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblAppointment deleteRow = dc.tblAppointments.FirstOrDefault(r => r.Id == id); if (deleteRow != null) { dc.tblAppointments.Remove(deleteRow); results = dc.SaveChanges(); if (rollback) { transaction.Rollback(); } } else { throw new Exception("Appointment was not found."); } } } }); return(results); } catch (Exception) { throw; } }
// POST: api/Appointment public IHttpActionResult Post([FromBody] AppointmentViewModel model) { try { if (model != null) { var appointment = new tblAppointment() { GlobalAppointmentId = model.GlobalAppointmentId, BusinessServiceId = model.BusinessServiceId, Title = model.Title, PatternType = model.PatternType, StartTime = model.StartTime, EndTime = model.EndTime, IsRecuring = model.IsRecuring, IsAllDayEvent = model.IsAllDayEvent, TextColor = model.TextColor, BackColor = model.BackColor, RecureEvery = model.RecureEvery, EndAfter = model.EndAfter, EndAfterDate = model.EndAfterDate, StatusType = model.StatusType, CancelReason = model.CancelReason, IsActive = model.IsActive, Created = model.Created, BusinessCustomerId = model.BusinessCustomerId, BusinessEmployeeId = model.BusinessEmployeeId, BusinessOfferId = model.BusinessOfferId, ServiceLocationId = model.ServiceLocationId }; _db.tblAppointments.Add(appointment); var response = _db.SaveChanges(); if (response > 0) { return(Ok(new { status = true, data = appointment })); } else { return(Ok(new { status = false, data = "There was a problem." })); } } else { return(Ok(new { status = false, data = "There was a problem." })); } } catch (Exception ex) { return(BadRequest(ex.Message.ToString())); } }
// GET: Appointments/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblAppointment tblAppointment = db.tblAppointments.Find(id); if (tblAppointment == null) { return(HttpNotFound()); } return(View(tblAppointment)); }
public ActionResult Create([Bind(Include = "Appointment_Id,Appointment_Date,Appointment_Time,Appointment_Type,Doctor_Code,Patient_Code,Appointment_Room,Appointment_Code,Status")] tblAppointment tblAppointment) { if (ModelState.IsValid) { tblAppointment.Status = "Pending"; db.tblAppointments.Add(tblAppointment); db.SaveChanges(); return(RedirectToAction("Index", "AppointmentHome")); } ViewBag.Doctor_Code = new SelectList(db.tblDoctors, "Doctor_Code", "Doctor_Name", tblAppointment.Doctor_Code); ViewBag.Patient_Code = new SelectList(db.tblPatients, "Patient_Code", "Patient_Name", tblAppointment.Patient_Code); return(View(tblAppointment)); }
public async static Task <bool> Insert(Appointment appointment, bool rollback = false) { try { int result = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblAppointment newRow = new tblAppointment(); newRow.Id = Guid.NewGuid(); newRow.CustomerId = appointment.CustomerId; newRow.EmployeeId = appointment.EmployeeId; newRow.StartDateTime = appointment.StartDateTime; newRow.EndDateTime = appointment.EndDateTime; newRow.ServiceId = appointment.ServiceId; newRow.Status = appointment.Status; // Backfill the id on the input parameter appointment appointment.Id = newRow.Id; // Insert the row dc.tblAppointments.Add(newRow); // Commit the changes and get the number of rows affected result = dc.SaveChanges(); if (rollback) { transaction.Rollback(); } } }); return(result == 1); } catch (Exception) { throw; } }
public void DeleteTest() { InsertTest(); int expected = 1; int actual = 0; tblAppointment deleteRow = dc.tblAppointments.Where(a => a.Id == appointmentId).FirstOrDefault(); if (deleteRow != null) { dc.tblAppointments.Remove(deleteRow); actual = dc.SaveChanges(); } Assert.AreEqual(expected, actual); }
// GET: Appointments/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblAppointment tblAppointment = db.tblAppointments.Find(id); if (tblAppointment == null) { return(HttpNotFound()); } ViewBag.Doctor_Code = new SelectList(db.tblDoctors, "Doctor_Code", "Doctor_Name", tblAppointment.Doctor_Code); ViewBag.Patient_Code = new SelectList(db.tblPatients, "Patient_Code", "Patient_Name", tblAppointment.Patient_Code); return(View(tblAppointment)); }
public void UpdateTest() { InsertTest(); int expected = 1; int actual = 0; tblAppointment updateRow = dc.tblAppointments.Where(a => a.Id == appointmentId).FirstOrDefault(); if (updateRow != null) { updateRow.Status = "In Progress"; actual = dc.SaveChanges(); } Assert.AreEqual(expected, actual); }
public async Task <ActionResult> cancelAppointment(int?appointmentID) { try { tblAppointment tblAppointment = await db.tblAppointments.FindAsync(appointmentID); db.tblClients.Remove(tblAppointment.tblClient); db.tblAppointments.Remove(tblAppointment); await db.SaveChangesAsync(); } catch (Exception) { ViewBag.searchError = "Your appointment could not be found please try again, or contact the Mobile Hairdresser"; } return(RedirectToAction("Search", "Appointment")); }
public async Task <ActionResult> cancelAppointmentConfirmation(int?appointmentID) { tblAppointment tblAppointment = await db.tblAppointments.FindAsync(appointmentID); if (((tblAppointment.appointmentDate - DateTime.Today).TotalDays <= 0) || (Session["user"] == null)) { ViewData["appointmentError"] = "We are unable to cancel any appointment on the same day." + "Please contact the Mobile Hairdresser's directly to cancel the appointment"; return(RedirectToAction(Request.UrlReferrer.ToString())); } else { db.tblAppointments.Remove(tblAppointment); await db.SaveChangesAsync(); return(RedirectToAction("Search", "Appointment")); } }
public ActionResult Details(int?id) { tblAppointment t = db.tblAppointments.SingleOrDefault(x => x.intAppointmentID == id); AppointmentModel A = new AppointmentModel() { AppointmentID = t.intAppointmentID, SlotID = (int)t.intSlotID, MemberID = (int)t.intMemberID, PatientName = t.strPatientName, PatientAge = (int)t.intPatientAge, PatientGender = t.strPatientGender, Notes = t.strNotes, IsNewCase = (bool)t.blnIsNewCase, OldCaseNo = t.strOldCaseNo, AppotimentTakenTime = (DateTime)t.dtmAppotimentTakenTime, }; return(View(A)); }
public ActionResult BookAppoitment(BookModel M) { tblAppointment ap = new tblAppointment(); ap.intSlotID = M.SlotID; ap.intMemberID = Convert.ToInt32(Session["memberid"]);// Session here ap.intPatientAge = M.PatientAge; ap.strNotes = M.Notes; ap.strOldCaseNo = M.OldCaseNo; ap.strPatientGender = M.PatientGender; ap.strPatientName = M.PatientName; ap.dtmAppotimentTakenTime = DateTime.Now; ap.blnIsNewCase = M.IsNewCase; db.tblAppointments.Add(ap); db.SaveChanges(); tblAppointmentSlot s = db.tblAppointmentSlots.SingleOrDefault(x => x.intSlotID == M.SlotID); if (s != null) { s.strStatus = "Booked"; db.SaveChanges(); //Mail Code Here String em = Session["email"].ToString(); String sub = "Your Appointment Booked"; String det = "\nAppointment ID " + ap.intAppointmentID; det += "\nFor :" + ap.strPatientName; SmtpClient cl = new SmtpClient("smtp.gmail.com", 587); cl.Credentials = new NetworkCredential("*****@*****.**", "fake123456"); cl.EnableSsl = true; MailMessage mg = new MailMessage("*****@*****.**", em, sub, det); cl.Send(mg); //If you get error in mail comment cl.send line } return(RedirectToAction("Index")); }
public ActionResult saveChangeAppointment(int?appointmentID, tblAppointment tblAppointment) { try { var findClientID = db.tblAppointments.Where(clientID => clientID.appointmentID == appointmentID).First(); if ((tblAppointment.appointmentDate - DateTime.Today).TotalDays <= 0) { TempData["appointmentError"] = "Sorry we are unable to change the appointment on the same day." + "Please contact Mobile Hairdresser's directly to make changes "; return(Redirect(Request.UrlReferrer.ToString())); } else { tblClient newClient = db.tblClients.Find(findClientID.clientID); { newClient.clientName = tblAppointment.tblClient.clientName; newClient.clientMobile = tblAppointment.tblClient.clientMobile; newClient.clientEmail = tblAppointment.tblClient.clientEmail; newClient.clientHouseNumber = tblAppointment.tblClient.clientHouseNumber; newClient.clientPostalCode = tblAppointment.tblClient.clientPostalCode; } tblAppointment newAppointment = db.tblAppointments.Find(tblAppointment.appointmentID); { newAppointment.employeeID = tblAppointment.employeeID; newAppointment.haircutID = tblAppointment.haircutID; newAppointment.timeSlotID = tblAppointment.timeSlotID; } db.SaveChanges(); return(RedirectToAction("confirmationEmail", "Appointment", new { appointmentID = tblAppointment.appointmentID })); } } catch (Exception) { TempData["appointmentError"] = "<p>Unable to make apppointment please try again later.</p>"; } return(RedirectToAction("Search", "Appointment")); }
public ActionResult Edit(AppointmentModel am) { tblAppointment a = db.tblAppointments.SingleOrDefault(x => x.intAppointmentID == am.AppointmentID); if (a != null) { a.intAppointmentID = am.AppointmentID; a.intSlotID = am.SlotID; a.intMemberID = am.MemberID; a.strPatientName = am.PatientName; a.intPatientAge = am.PatientAge; a.strPatientGender = am.PatientGender; a.strNotes = am.Notes; a.blnIsNewCase = am.IsNewCase; a.strOldCaseNo = am.OldCaseNo; a.dtmAppotimentTakenTime = am.AppotimentTakenTime; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult ViewStatus(tblAppointment a) { var db = new ClinicEntities2(); var g = db.tblAppointments.Where(x => x.Patient_Code == a.Patient_Code ).FirstOrDefault(); //var d=db.tblDoctors.Where(x=>x.Doctor_Code ) try { if (g != null) { Session["PatientCode"] = g.Patient_Code.ToString(); ViewBag.Status = g.Status; } } catch (Exception ex) { } return(View(a)); }
public ActionResult Create(AppointmentModel A) { tblAppointment ap = new tblAppointment(); ap.intSlotID = A.SlotID; ap.intMemberID = A.MemberID; ap.strPatientName = A.PatientName; ap.intPatientAge = A.PatientAge; ap.strPatientGender = A.PatientGender; ap.strNotes = A.Notes; ap.blnIsNewCase = A.IsNewCase; ap.strOldCaseNo = A.OldCaseNo; ap.dtmAppotimentTakenTime = A.AppotimentTakenTime; db.tblAppointments.Add(ap); db.SaveChanges(); //Mail Code Here String em = Session["email"].ToString(); String sub = "Your Appointment Booked"; String det = "\nAppointment ID " + ap.intAppointmentID; det += "\nFor :" + A.PatientName; SmtpClient cl = new SmtpClient("smtp.gmail.com", 587); cl.Credentials = new NetworkCredential("*****@*****.**", "fake123456"); cl.EnableSsl = true; MailMessage mg = new MailMessage("*****@*****.**", em, sub, det); cl.Send(mg); return(RedirectToAction("Index")); }
public ActionResult Delete(int?id) { tblAppointment t = db.tblAppointments.SingleOrDefault(x => x.intAppointmentID == id); if (t == null) { Response.Redirect("../Login/Authenticate"); } AppointmentModel A = new AppointmentModel() { AppointmentID = t.intAppointmentID, SlotID = (int)t.intSlotID, MemberID = (int)t.intMemberID, PatientName = t.strPatientName, PatientAge = (int)t.intPatientAge, PatientGender = t.strPatientGender, Notes = t.strNotes, IsNewCase = (bool)t.blnIsNewCase, OldCaseNo = t.strOldCaseNo, AppotimentTakenTime = (DateTime)t.dtmAppotimentTakenTime, }; return(View(A)); }
public ActionResult DownloadAppointmentCard(int?appointmentID) { tblAppointment tblAppointment = db.tblAppointments.Find(appointmentID); tblEmployee tblEmployee = db.tblEmployees.Find(tblAppointment.employeeID); tblHaircut tblHaircut = db.tblHaircuts.Find(tblAppointment.haircutID); tblTimeSlot tblTimeSlot = db.tblTimeSlots.Find(tblAppointment.timeSlotID); ViewData["employee"] = tblEmployee.FirstName + " " + tblEmployee.LastName; ViewData["haircut"] = tblHaircut.HaircutName; ViewData["timeSlot"] = tblTimeSlot.timeSlot; if (TempData["userInfo"] != null) { TempData.Keep("userInfo"); } return(new Rotativa.ViewAsPdf("appointmentConfirmation", tblAppointment) { FileName = "Mobile Hairdresser : Appointment Card.pdf", PageSize = Size.A4, PageOrientation = Orientation.Portrait, PageMargins = { Left = 0, Right = 0 }, CustomSwitches = "--print-media-type --zoom 1.3" }); }
public ActionResult bookAppointment(tblAppointment tblAppointment, tblClient tblClient) { if (ModelState.IsValid) { if ((tblAppointment.appointmentDate - DateTime.Today).TotalDays <= 0) { ViewData["appointmentError"] = "We are unable to create appointment for the same day."; if (Request.UrlReferrer.ToString() != null) { return(Redirect(Request.UrlReferrer.ToString())); } else { return(RedirectToAction("appointmentIndex", "Appointment")); } } else { try { var salt = Crypto.GenerateSalt(); var generatedPassword = Membership.GeneratePassword(12, 1); TempData["userInfo"] = generatedPassword.ToString(); int appointmentTime = int.Parse(Request["appointmentTime"]); tblClient newClient = new tblClient(); { newClient.clientName = tblAppointment.tblClient.clientName; newClient.clientMobile = tblAppointment.tblClient.clientMobile; newClient.clientEmail = tblAppointment.tblClient.clientEmail; newClient.clientHouseNumber = tblAppointment.tblClient.clientHouseNumber; newClient.clientPostalCode = tblAppointment.tblClient.clientPostalCode; newClient.salt = salt; newClient.Password = Crypto.HashPassword(generatedPassword + salt).ToString(); } db.tblClients.Add(newClient); db.SaveChanges(); tblAppointment newAppointment = new tblAppointment(); { newAppointment.appointmentDate = tblAppointment.appointmentDate; newAppointment.clientID = newClient.clientID; newAppointment.employeeID = tblAppointment.employeeID; newAppointment.haircutID = tblAppointment.haircutID; newAppointment.timeSlotID = appointmentTime; } using (db) { db.tblAppointments.Add(newAppointment); db.SaveChanges(); } int findAppointmentID = newAppointment.appointmentID; return(RedirectToAction("confirmationEmail", "Appointment", new { appointmentID = findAppointmentID })); } catch (Exception) { TempData["appointmentError"] = "<p>Unable to make apppointment please try again later.</p>"; } } } return(RedirectToAction("appointmentIndex", "Appointment")); }