public IHttpActionResult GetFaqs() { List <Faq> faqs = db.Faqs.ToList(); List <FaqDto> faqDtos = new List <FaqDto> { }; //Here you can choose which information is exposed to the API foreach (var faq in faqs) { FaqDto newFaq = new FaqDto { FaqID = faq.FaqID, Question = faq.Question, Answer = faq.Answer, Publish = faq.Publish, DepartmentID = faq.DepartmentID, }; if (faq.Department != null) { newFaq.DepartmentName = faq.Department.DepartmentName; } faqDtos.Add(newFaq); } return(Ok(faqDtos)); }
public IHttpActionResult ListFaqs(string FaqSearchKey = null) { List <Faq> faqs; if (FaqSearchKey != null) { faqs = db.Faqs.Where(t => t.FaqQuestion.Contains(FaqSearchKey) || t.FaqAnswer.Contains(FaqSearchKey)).ToList(); } else { faqs = db.Faqs.ToList(); } List <FaqDto> faqDtos = new List <FaqDto> { }; //Find to list everything and a way to read the search key!--- foreach (var faq in faqs) { FaqDto NewFaq = new FaqDto { FaqID = faq.FaqID, FaqQuestion = faq.FaqQuestion, FaqAnswer = faq.FaqAnswer, CategoryID = faq.CategoryID }; faqDtos.Add(NewFaq); } return(Ok(faqDtos)); }
public ActionResult Details(int id) { ShowFaq ViewModel = new ShowFaq(); ViewModel.isadmin = User.IsInRole("Admin"); string url = "FaqData/FindFaq/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Debug.WriteLine(response.StatusCode); if (response.IsSuccessStatusCode) { FaqDto SelectedFaqs = response.Content.ReadAsAsync <FaqDto>().Result; ViewModel.Faq = SelectedFaqs; //Find the Category for Project by Id url = "CategoryData/FindCategoryForFaq/" + id; response = client.GetAsync(url).Result; Debug.WriteLine(response.StatusCode); CategoryDto SelectedCategory = response.Content.ReadAsAsync <CategoryDto>().Result; ViewModel.Categories = SelectedCategory; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public ActionResult Edit(int id) { UpdateFaq ViewModel = new UpdateFaq(); string url = "faqdata/findfaq/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Can catch the status code (200 OK, 301 REDIRECT), etc. //Debug.WriteLine(response.StatusCode); if (response.IsSuccessStatusCode) { //Put data into faq data transfer object FaqDto SelectedFaq = response.Content.ReadAsAsync <FaqDto>().Result; ViewModel.faq = SelectedFaq; //get information about departments assoc w/ FAQ's. url = "departmentsdata/getdepartments"; response = client.GetAsync(url).Result; IEnumerable <DepartmentsDto> PotentialDepartments = response.Content.ReadAsAsync <IEnumerable <DepartmentsDto> >().Result; ViewModel.departments = PotentialDepartments; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public void copy(Faq faq, FaqDto faqDto) { faq.faq_id = faqDto.faq_id; faq.question = faqDto.question; faq.answer = faqDto.answer; faq.is_active = faqDto.is_active; }
public ActionResult Update(int id) { CreateFaq ViewModel = new CreateFaq(); string url = "FaqData/FindFaq/" + id; HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { FaqDto selectedFaq = response.Content.ReadAsAsync <FaqDto>().Result; ViewModel.faq = selectedFaq; url = "CategoryData/ListCategories"; response = client.GetAsync(url).Result; IEnumerable <CategoryDto> PotentialCategories = response.Content.ReadAsAsync <IEnumerable <CategoryDto> >().Result; ViewModel.allCategories = PotentialCategories; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public IHttpActionResult FindFaq(int id) { Faq faq = db.Faqs.Find(id); FaqDto faqDto = new FaqDto { FaqID = faq.FaqID, Question = faq.Question, Answer = faq.Answer, Publish = faq.Publish, DepartmentID = faq.DepartmentID }; return(Ok(faqDto)); }
public IActionResult edit(long faq_id) { try { var faq = _faqRepository.getById(faq_id); FaqDto faqDto = _mapper.Map <FaqDto>(faq); RouteData.Values.Remove("faq_id"); return(View(faqDto)); } catch (Exception ex) { AlertHelper.setMessage(this, ex.Message, messageType.error); return(RedirectToAction("index")); } }
public ActionResult DeleteConfirm(int id) { string url = "FaqData/FindFaq/" + id; HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { FaqDto SelectedFaq = response.Content.ReadAsAsync <FaqDto>().Result; return(View(SelectedFaq)); } else { return(RedirectToAction("Error")); } }
public IActionResult edit(FaqDto faqDto) { try { if (ModelState.IsValid) { _faqService.update(faqDto); AlertHelper.setMessage(this, "Faq updated successfully."); return(RedirectToAction("index")); } } catch (Exception ex) { AlertHelper.setMessage(this, ex.Message, messageType.error); } return(View(faqDto)); }
public IHttpActionResult FindFaq(int id) { Faq faq = db.Faqs.Find(id); if (faq == null) { return(NotFound()); } FaqDto faqDto = new FaqDto { FaqID = faq.FaqID, FaqQuestion = faq.FaqQuestion, FaqAnswer = faq.FaqAnswer, CategoryID = faq.CategoryID }; return(Ok(faqDto)); }
public ActionResult DeleteConfirm(int id) { string url = "faqdata/findfaq/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Can catch the status code (200 OK, 301 REDIRECT), etc. //Debug.WriteLine(response.StatusCode); if (response.IsSuccessStatusCode) { //Put data into faq data transfer object FaqDto SelectedFaq = response.Content.ReadAsAsync <FaqDto>().Result; return(View(SelectedFaq)); } else { return(RedirectToAction("Error")); } }
public void save(FaqDto faqDto) { try { using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required)) { Faq faq = new Faq(); _faqMaker.copy(faq, faqDto); _faqRepository.insert(faq); tx.Complete(); } } catch (Exception) { throw; } }
public IHttpActionResult ListFaqs() { List <Faq> faqs = db.Faqs.ToList(); List <FaqDto> faqDtos = new List <FaqDto>(); foreach (var item in faqs) { FaqDto NewFaq = new FaqDto { FaqID = item.FaqID, Answer = item.Answer, Question = item.Question, CategoryID = item.CategoryID }; faqDtos.Add(NewFaq); } return(Ok(faqDtos)); }
public IHttpActionResult FindFaq(int id) { Faq faq = db.Faqs.Find(id); if (faq == null) { return(NotFound()); } FaqDto selectedFaq = new FaqDto { FaqID = faq.FaqID, Answer = faq.Answer, Question = faq.Question, CategoryID = faq.CategoryID }; return(Ok(selectedFaq)); }
// GET: Faq/Details/5 public ActionResult Details(int id) { ShowFaq ViewModel = new ShowFaq(); string url = "faqdata/findfaq/" + id; HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { //Add this API data to faq DTO FaqDto SelectedFaq = response.Content.ReadAsAsync <FaqDto>().Result; ViewModel.faq = SelectedFaq; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public IHttpActionResult GetFaqsForCategory(int id) { List <Faq> faqs = db.Faqs.Where(t => t.CategoryID == id) .ToList(); List <FaqDto> faqDtos = new List <FaqDto> { }; foreach (var faq in faqs) { FaqDto NewFaq = new FaqDto { FaqID = faq.FaqID, FaqQuestion = faq.FaqQuestion, FaqAnswer = faq.FaqAnswer, CategoryID = faq.CategoryID }; faqDtos.Add(NewFaq); } return(Ok(faqDtos)); }
public IHttpActionResult GetFaqs() { IEnumerable <Faq> Faqs = db.Faqs.ToList(); List <FaqDto> FaqDtos = new List <FaqDto> { }; //Here you can choose which information is exposed to the API foreach (var Faq in Faqs) { FaqDto NewFaq = new FaqDto { faq_id = Faq.faq_id, question = Faq.question, answer = Faq.answer, DepartmentName = Faq.Department.DepartmentName, }; FaqDtos.Add(NewFaq); } return(Ok(FaqDtos)); }
public void update(FaqDto faqDto) { try { using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required)) { Faq faq = _faqRepository.getById(faqDto.faq_id); if (faq == null) { throw new ItemNotFoundException($"Faq with ID {faqDto.faq_id} doesnot Exit."); } _faqMaker.copy(faq, faqDto); _faqRepository.update(faq); tx.Complete(); } } catch (Exception) { throw; } }
public ActionResult Edit(int id) { //Model used to combine a faq object and departments list for dropdown EditFaq modelView = new EditFaq(); //Get the current ParkingSpot object string url = "FaqData/FindFaq/" + id; HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { FaqDto SelectedFaq = response.Content.ReadAsAsync <FaqDto>().Result; modelView.Faq = SelectedFaq; } else { return(RedirectToAction("Error")); } //The view needs to be sent a list of all the Departments so the client can select a Department for FAQ in the view modelView.DepartmentsSelectList = GetDepartmentSelectList(); return(View(modelView)); }
public IHttpActionResult FindFaq(int id) { //find the Faq data Faq Faq = db.Faqs.Find(id); //does db search and if results come back, //We continue, if not, return error not found. if (Faq == null) { return(NotFound()); } //Put into Dto form FaqDto FaqDto = new FaqDto { faq_id = Faq.faq_id, question = Faq.question, answer = Faq.answer, DepartmentName = Faq.Department.DepartmentName, }; return(Ok(FaqDto)); }
public IHttpActionResult GetAllFaqForCategory() { List <Faq> faqs = db.Faqs.ToList(); List <Category> categories = db.Categories.ToList(); List <FaqDto> faqDtos = new List <FaqDto> { }; var faqxcategory = from c in db.Categories join f in db.Faqs on c.CategoryID equals f.CategoryID into table1 from f in table1.ToList() select new { category = c, faqs = f }; foreach (var faq in faqxcategory) { FaqDto NewFaq = new FaqDto { FaqID = faq.faqs.FaqID, FaqQuestion = faq.faqs.FaqQuestion, FaqAnswer = faq.faqs.FaqAnswer, CategoryID = faq.faqs.CategoryID, }; faqDtos.Add(NewFaq); } return(Ok(faqDtos)); }
public ActionResult Edit(int id) { UpdateFaq ViewModel = new UpdateFaq(); string url = "FaqData/FindFaq/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Debug.WriteLine(response.StatusCode); if (response.IsSuccessStatusCode) { FaqDto SelectedFaqs = response.Content.ReadAsAsync <FaqDto>().Result; ViewModel.Faq = SelectedFaqs; url = "CategoryData/GetCategories"; response = client.GetAsync(url).Result; IEnumerable <CategoryDto> FaqsCategory = response.Content.ReadAsAsync <IEnumerable <CategoryDto> >().Result; ViewModel.Allcategories = FaqsCategory; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public IHttpActionResult GetFaqsByCategoryId(int id) { List <Faq> faqList = db.Faqs.Where(f => f.CategoryID == id).ToList(); List <FaqDto> faqDtos = new List <FaqDto>(); if (faqList == null) { return(NotFound()); } foreach (var item in faqList) { FaqDto NewFaq = new FaqDto { FaqID = item.FaqID, Answer = item.Answer, Question = item.Question, CategoryID = item.CategoryID }; faqDtos.Add(NewFaq); } return(Ok(faqDtos)); }