public async Task <IHttpActionResult> Putfaq(int id, faq faq) { var findFAQs = await db.faqs.Where(a => a.id == id).FirstOrDefaultAsync(); if (findFAQs != null) { findFAQs.title = faq.title; findFAQs.body = faq.body; db.Entry(findFAQs).State = EntityState.Modified; int check = await db.SaveChangesAsync(); if (check > 0) { return(Ok(await db.faqs.ToListAsync())); } else { return(BadRequest("Update fails.")); } } else { return(BadRequest("FAQs not found.")); } }
public ActionResult DeleteConfirmed(int id) { try { if (Session["role"] != null) { if (Session["role"].ToString() == "ADM") { faq faq = db.faqs.Find(id); db.faqs.Remove(faq); db.SaveChanges(); return(RedirectToAction("Index")); } } else { return(View("~/Views/LabTestResults/NotLoggedIn.cshtml")); } } catch (DbUpdateException e) { ViewBag.DbExceptionMessage = e.Message; } catch (SqlException sqlException) { TempData["SqlException"] = sqlException.Message; } catch (Exception genericException) { TempData["SqlException"] = genericException.Message; } return(RedirectToAction("Delete", new { id = id })); }
// GET: faqs/Details/5 public ActionResult Details(int?id) { try { if (Session["role"] != null) { if (Session["role"].ToString() == "ADM") { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } faq faq = db.faqs.Find(id); if (faq == null) { return(HttpNotFound()); } return(View(faq)); } } else { return(View("~/Views/LabTestResults/NotLoggedIn.cshtml")); } } catch (Exception genericException) { ViewBag.ExceptionMessage = genericException.Message; } return(View("~/Views/Errors/Details.cshtml")); }
public List <faq> Read() { List <faq> faqs = new List <faq>(); using (SqlConnection connection = new SqlConnection(DataSettings.CONNECTION_STRING)) { connection.Open(); StringBuilder sb = new StringBuilder(); sb.Append("SELECT [FaqID],[Question],[Answer],[Website],[ApplicantQ]"); sb.Append("FROM [careerfair].[faq]"); String sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { faq faq = new faq(); faq.FaqID = DatabaseHelper.CheckNullInt(reader, 0); faq.Question = DatabaseHelper.CheckNullString(reader, 1); faq.Answer = DatabaseHelper.CheckNullString(reader, 2); faq.Website = DatabaseHelper.CheckNullString(reader, 3); faq.IsApplicantQ = DatabaseHelper.CheckNullBool(reader, 4); faqs.Add(faq); } } } } return(faqs); }
public JsonResult Get(int id) { var kundeserviceDb = new KundeServiceDB(_dbcontext); faq enFaq = kundeserviceDb.hentEnFaq(id); return(Json(enFaq)); }
public static string Import(Stream xmlFile) { string output = string.Empty; try { TextReader rdr = new StreamReader(xmlFile); XElement x = XElement.Load(rdr); var faqs = from p in x.Descendants("faq") select p; foreach (XElement xe in faqs) { dbDataContext db = new dbDataContext(); faq f = new faq(); f.title = xe.FirstAttribute.Value; f.body = xe.Value; db.faqs.InsertOnSubmit(f); try { db.SubmitChanges(); //inefficient to submit each time, *but* this will tell which faqs got inserted and which didn't output += "<div class='success'>-" + xe.FirstAttribute.Value + " " + Resources.Common.Updated + "</div>"; } catch// (Exception ex) { output += "<div class='error'>" + Resources.Common.Error + " " + xe.FirstAttribute.Value + "</div>"; } } } catch (Exception ex) { output = "<div class='error'>" + Resources.Common.Error + ": <div class='sub_error'>" + ex.Message + "</div></div>"; } return output; }
public ActionResult FaqDetails(int id) { DAL.FaqDAL.FAQRepository FaqRepo = new FAQRepository(); faq _faq = FaqRepo.SelectOne(id); return(View(_faq)); }
public void Insert(faq faq) { //faq.FaqID = NextIdValue(); //_faqs.Add(faq); _ds.Insert(faq); }
public ActionResult DeleteConfirmed(int id) { faq faq = db.faqs.Find(id); db.faqs.Remove(faq); db.SaveChanges(); return(RedirectToAction("Index")); }
public static void Add(dbDataContext db, string q, string a) { faq f = new faq(); f.title = q; f.body = a; db.faqs.InsertOnSubmit(f); db.SubmitChanges(); }
public bool commitInsert(faq qa) { using (obj) { //inserting into database obj.faqs.InsertOnSubmit(qa); obj.SubmitChanges(); return(true); } }
public ActionResult Edit([Bind(Include = "Id,Question,Answer")] faq faq) { if (ModelState.IsValid) { db.Entry(faq).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(faq)); }
public ActionResult Create([Bind(Include = "Id,Question,Answer")] faq faq) { if (ModelState.IsValid) { db.faqs.Add(faq); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(faq)); }
public void Update(faq faq) { var oldFAQ = _faqs.Where(f => f.FaqID == faq.FaqID).FirstOrDefault(); if (oldFAQ != null) { _faqs.Remove(oldFAQ); _faqs.Add(faq); _ds.Update(faq); } }
public ActionResult Create([Bind(Include = "id,question,answer,category_id")] faq faq) { try { if (Session["role"] != null) { if (Session["role"].ToString() == "ADM" || Session["role"].ToString() == "PAT" || Session["role"].ToString() == "USR") { if (ModelState.IsValid) { if (Session["userId"] != null) { faq.publisher_id = Convert.ToInt32(Session["userId"]); } else { faq.publisher_id = 0; } faq.date_created = System.DateTime.Now; db.faqs.Add(faq); db.SaveChanges(); ViewBag.questionAdd = "Thank you for your question! Our staff will look into providing an asnwer!"; if (Session["role"].ToString() == "ADM") { return(RedirectToAction("Index")); } } ViewBag.category_id = new SelectList(db.categories, "id", "name", faq.category_id); //ViewBag.publisher_id = new SelectList(db.users, "id", "username", faq.publisher_id); return(View(faq)); } } else { return(View("~/Views/LabTestResults/NotLoggedIn.cshtml")); } } catch (DbUpdateException e) { ViewBag.DbExceptionMessage = e.Message; } catch (SqlException e) { ViewBag.SqlExceptionMessage = e.Message; } catch (Exception genericException) { ViewBag.ExceptionMessage = genericException.Message; } return(View("~/Views/Errors/Details.cshtml")); }
public JsonResult Post([FromBody] faq innFaq) { if (ModelState.IsValid) { var kundeserviceDb = new KundeServiceDB(_dbcontext); bool OK = kundeserviceDb.largeEnFaq(innFaq); if (OK) { return(Json("Opprettelse av ny FAQ var suksessfult!")); } } return(Json("Opprettelse av ny FAQ feilet!")); }
public JsonResult Put(int id, [FromBody] faq innFaq) { if (ModelState.IsValid) { var kundeserviceDb = new KundeServiceDB(_dbcontext); bool OK = kundeserviceDb.endreEnFaq(id, innFaq); if (OK) { return(Json("FAQ endret!")); } } return(Json("Endring av FAQ feilet!")); }
public async Task <IHttpActionResult> Getfaq(int id) { faq faq = await db.faqs.Where(a => a.id == id).FirstOrDefaultAsync(); if (faq != null) { return(Ok(faq)); } else { return(BadRequest("FAQs not found.")); } }
public ActionResult Delete(int id, faq qa) { //deletes an location based on id try { obj.commitDelete(id); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult FaqDelete(int id, faq _faq) { try { DAL.FaqDAL.FAQRepository FaqRepo = new FAQRepository(); FaqRepo.Delete(id); return(RedirectToAction("FaqPage")); } catch { return(View()); } }
public faq hentEnFaq(int id) { //Bruker FirstOrDefault etter som at lazy loading ikke støttes av core FAQ enDBFaq = _dbcontext.AlleFaq.FirstOrDefault(f => f.id == id); var enFaq = new faq() { id = enDBFaq.id, sporsmal = enDBFaq.sporsmal, svar = enDBFaq.svar }; return(enFaq); }
// GET: faqsAdmin/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } faq faq = db.faqs.Find(id); if (faq == null) { return(HttpNotFound()); } return(View(faq)); }
public ActionResult FaqCreate(faq _faq) { try { DAL.FaqDAL.FAQRepository FaqRepo = new FAQRepository(); FaqRepo.Insert(_faq); return(RedirectToAction("FaqPage")); } catch { return(View()); } }
public async Task <IHttpActionResult> Postfaq(faq faq) { faq.create_at = DateTime.Now; db.faqs.Add(faq); int check = await db.SaveChangesAsync(); if (check > 0) { return(Ok(await db.faqs.ToListAsync())); } else { return(BadRequest("Create fails")); } }
public ActionResult Insert(faq qa) { //Inserting into the table if (ModelState.IsValid) { try { obj.commitInsert(qa); return(RedirectToAction("Index")); } catch { return(View()); } } return(View()); }
public void Remove(faq faq) { using (SqlConnection connection = new SqlConnection(DataSettings.CONNECTION_STRING)) { connection.Open(); StringBuilder sb = new StringBuilder(); sb.Append("DELETE FROM [careerfair].[faq]"); sb.Append("WHERE [FaqID] = " + faq.FaqID); String sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = System.Data.CommandType.Text; command.ExecuteNonQuery(); } } }
public ActionResult Update(int id, faq qa) { //updating a faq based on id if (ModelState.IsValid) { try { obj.commitUpdate(id, qa.question, qa.answer); return(RedirectToAction("Details/" + id)); } catch { return(View()); } } return(View()); }
public ActionResult Edit([Bind(Include = "id,question,answer,category_id")] faq faq) { try { if (Session["role"] != null) { if (Session["role"].ToString() == "ADM") { if (ModelState.IsValid) { int pub_id = Convert.ToInt16(Session["userId"]); faq.publisher_id = pub_id; faq.date_created = DateTime.Now; db.Entry(faq).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.category_id = new SelectList(db.categories, "id", "name", faq.category_id); return(View(faq)); } } else { return(View("~/Views/LabTestResults/NotLoggedIn.cshtml")); } } catch (DbUpdateException e) { ViewBag.DbExceptionMessage = e.Message; } catch (SqlException sqlException) { ViewBag.SqlExceptionMessage = sqlException.Message; } catch (Exception exception) { ViewBag.genericException = exception.Message; } return(View("~/Views/Errors/Details.cshtml")); }
// GET: faqs/Edit/5 public ActionResult Edit(int?id) { try { if (Session["role"] != null) { if (Session["role"].ToString() == "ADM") { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } faq faq = db.faqs.Find(id); if (faq == null) { return(HttpNotFound()); } ViewBag.category_id = new SelectList(db.categories, "id", "name", faq.category_id); return(View(faq)); } } else { return(View("~/Views/LabTestResults/NotLoggedIn.cshtml")); } } catch (DbUpdateException e) { ViewBag.DbExceptionMessage = e.Message; } catch (SqlException e) { ViewBag.SqlExceptionMessage = e.Message; } catch (Exception genericException) { ViewBag.ExceptionMessage = genericException.Message; } return(View("~/Views/Errors/Details.cshtml")); }
public bool largeEnFaq(faq innFaq) { var nyFaq = new FAQ { id = innFaq.id, sporsmal = innFaq.sporsmal, svar = innFaq.svar }; try { _dbcontext.AlleFaq.Add(nyFaq); _dbcontext.SaveChanges(); } catch (Exception error) { return(false); } return(true); }
public void Insert(faq faq) { using (SqlConnection connection = new SqlConnection(DataSettings.CONNECTION_STRING)) { connection.Open(); StringBuilder sb = new StringBuilder(); sb.Append("INSERT INTO [careerfair].[faq]([Question],[Answer],[Website],[ApplicantQ])"); string values = "VALUES(@param1, @param2, @param3, @param4)"; sb.Append(values); String sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.Add("@param1", SqlDbType.NVarChar, int.MaxValue).Value = (object)faq.Question ?? DBNull.Value; command.Parameters.Add("@param2", SqlDbType.NVarChar, int.MaxValue).Value = (object)faq.Answer ?? DBNull.Value; command.Parameters.Add("@param3", SqlDbType.NVarChar, int.MaxValue).Value = (object)faq.Website ?? DBNull.Value; command.Parameters.Add("@param4", SqlDbType.Bit).Value = (object)faq.IsApplicantQ ?? DBNull.Value; command.CommandType = System.Data.CommandType.Text; command.ExecuteNonQuery(); } } }
public void Update(faq faq) { using (SqlConnection connection = new SqlConnection(DataSettings.CONNECTION_STRING)) { connection.Open(); StringBuilder sb = new StringBuilder(); sb.Append("UPDATE [careerfair].[faq]"); sb.Append("SET [Question] = @param1, [Answer] = @param2, [Website] = @param3, [ApplicantQ] = @param4 "); sb.Append("WHERE [FaqID] = " + faq.FaqID); String sql = sb.ToString(); using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.Add("@param1", SqlDbType.NVarChar, int.MaxValue).Value = (object)faq.Question ?? DBNull.Value; command.Parameters.Add("@param2", SqlDbType.NVarChar, int.MaxValue).Value = (object)faq.Answer ?? DBNull.Value; command.Parameters.Add("@param3", SqlDbType.NVarChar, int.MaxValue).Value = (object)faq.Website ?? DBNull.Value; command.Parameters.Add("@param4", SqlDbType.Bit).Value = (object)faq.IsApplicantQ ?? DBNull.Value; command.CommandType = System.Data.CommandType.Text; command.ExecuteNonQuery(); } } }
partial void Deletefaq(faq instance);
partial void Updatefaq(faq instance);
partial void Insertfaq(faq instance);