public IActionResult productaction(ProdViewModels addproduct) { if (ModelState.IsValid) { Product addnew = _context.Products.SingleOrDefault(product => product.Name == addproduct.Name); if (addnew != null) { ViewBag.Message = "This product already exists in the database. Add something else!"; return(View("Index", addproduct)); } Product AddProductinDB = new Product { Name = addproduct.Name, Description = addproduct.Description, Price = addproduct.Price, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; _context.Add(AddProductinDB); _context.SaveChanges(); AddProductinDB = _context.Products.SingleOrDefault(product => product.Name == AddProductinDB.Name); HttpContext.Session.SetInt32("ProductId", AddProductinDB.ProductId); return(RedirectToAction("ShowP")); } else { return(View("Index", addproduct)); } }
public ActionResult MedicCreate(Medic medic) { if (ModelState.IsValid) { MedicComparer med = new MedicComparer(); int ok = 1; if (db.Medics.Count() > 0) { foreach (var a in db.Medics) { if (med.Equals(a, medic)) { ok = 0; } } } if (ok == 1) { medic.idMedic = 1; db.Medics.Add(medic); db.SaveChanges(); TempData["Success"] = "Medic successfully submitted!"; return(RedirectToAction("MedicIndex")); } else { TempData["Warning"] = "Medic already exists!"; return(RedirectToAction("MedicEdit")); } } return(View()); }
public JsonResult SelectPotion(int id) { var context = new PCContext(); var potion = context.Potions .Where(m => m.Id == id) .FirstOrDefault(); if (potion != null) { WebSocketManager.Broadcast(new ServerMessage() { Command = ServerMessage.Commands.Selected, Content = POTION_HTML_ID_PREFIX + id }); if (!potion.Selected) { potion.Selected = true; context.SaveChanges(); } return(Json(new JsonResponse <string>() { Code = 200, Result = potion.Description }, JsonRequestBehavior.AllowGet)); } else { return(Json(new JsonResponse <string>() { Code = 404, Result = "Not found" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult MedicalRecordCreate(medicalRecord medicalRecord) { if (ModelState.IsValid) { int ok = 1; if (ok == 1) { medicalRecord.idmedicalRecords = 1; db.medicalRecords.Add(medicalRecord); db.SaveChanges(); TempData["Success"] = "Medical Record successfully submitted!"; return(RedirectToAction("PatientIndex", "Patient")); } else { TempData["Warning"] = "Medical Record already exists associated to this pacient!"; return(RedirectToAction("PatientIndex", "Patient")); } } return(View()); }
public ActionResult MedicalPrescriptionCreate(medicalPrescription medicalPrescription) { if (ModelState.IsValid) { int ok = 1; if (ok == 1) { medicalPrescription.idmedicalPrescription = 1; db.medicalPrescriptions.Add(medicalPrescription); db.SaveChanges(); TempData["Success"] = "Medical Prescription successfully submitted!"; return(RedirectToAction("AppointmentIndex", "Appointment")); } else { TempData["Warning"] = "Medical Prescription already exists associated to this pacient!"; return(RedirectToAction("AppointmentIndex", "Appointment")); } } return(View()); }
public ActionResult CreateAssistant(Assistant assistant) { try { if (ModelState.IsValid) { AssistantComparer cmp = new AssistantComparer(); int ok = 1; if (db.Assistants.Count() > 0) { foreach (var a in db.Assistants) { if (cmp.Equals(a, assistant)) { ok = 0; } } } if (ok == 1) { assistant.idMedic = 1; db.Assistants.Add(assistant); db.SaveChanges(); TempData["Success"] = "Assistant successfully created!"; return(RedirectToAction("IndexAssistant")); } else { TempData["Warning"] = "Assistant already exists!"; return(RedirectToAction("CreateAssistant")); } } return(RedirectToAction("IndexAssistant")); } catch { return(View()); } }
public ActionResult PatientCreate(Patient patient) { if (ModelState.IsValid) { PatientComparer cmp = new PatientComparer(); int ok = 1; if (db.Patients.Count() > 0) { foreach (var a in db.Patients) { if (cmp.Equals(a, patient)) { ok = 0; } } } if (ok == 1) { patient.idMedic = 1; medicalRecord m = new medicalRecord(); db.medicalRecords.Add(m); db.SaveChanges(); patient.idmedicalRecords = db.medicalRecords.ToList().Last().idmedicalRecords; db.Patients.Add(patient); db.SaveChanges(); TempData["Success"] = "Patient successfully added to the database!"; return(RedirectToAction("PatientIndex")); } else { TempData["Warning"] = "Patient already exists in the database!"; return(RedirectToAction("PatientCreate")); } } return(View()); }
public ActionResult AppointmentCreate(Appointment appointment) { if (ModelState.IsValid) { AppointmentComparer cmp = new AppointmentComparer(); int ok = 1; if (db.Appointments.Count() > 0) { foreach (var a in db.Appointments) { if (cmp.Equals(a, appointment)) { ok = 0; } } } if (ok == 1) { appointment.idMedic = 1; medicalPrescription m = new medicalPrescription(); m.Diagnostic = "To be completed"; m.Medication = "To be completed"; m.Free = true; db.medicalPrescriptions.Add(m); db.SaveChanges(); appointment.idmedicalPrescription = db.medicalPrescriptions.ToList().Last().idmedicalPrescription; db.Appointments.Add(appointment); db.SaveChanges(); TempData["Success"] = "Appointment successfully submitted!"; return(RedirectToAction("AppointmentIndex")); } else { String[] availableHours = new String[] { "9:00", "9:30", "10:00", "10:30", "11:00", "11:30", "12:00", "12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30", "16:00", "16:30" }; TimeSpan time = (TimeSpan)appointment.Time; String[] notAvailableHours = new String[20]; int k = 0; if (db.Appointments.Count() > 0) { foreach (var a in db.Appointments) { if (a.Date.Equals(appointment.Date)) { TimeSpan time1 = (TimeSpan)a.Time; notAvailableHours[k++] = time1.ToString().Split(':')[0] + ":" + time1.ToString().Split(':')[1]; } } } String content = ""; int ok1; for (int i = 0; i < availableHours.Length; i++) { ok1 = 1; for (int j = 0; j < k; j++) { if (notAvailableHours[j].Equals(availableHours[i])) { ok1 = 0; } } if (ok1 == 1) { content = content + availableHours[i] + " | "; } } TempData["Warning"] = "Appointment already booked! Times available this day are: " + content; } } return(View()); }
public Categoria Post([FromBody] Categoria cat) { _context.Categorias.Add(cat); _context.SaveChanges(); return(cat); }