Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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"));
            }
        }
Ejemplo n.º 4
0
        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"));
            }
        }
Ejemplo n.º 7
0
        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));
        }
Ejemplo n.º 8
0
        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"));
            }
        }
Ejemplo n.º 10
0
 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));
 }
Ejemplo n.º 11
0
        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));
        }
Ejemplo n.º 12
0
        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"));
            }
        }
Ejemplo n.º 13
0
        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;
            }
        }
Ejemplo n.º 14
0
        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));
        }
Ejemplo n.º 15
0
        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));
        }
Ejemplo n.º 16
0
        // 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"));
            }
        }
Ejemplo n.º 17
0
        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));
        }
Ejemplo n.º 19
0
        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;
            }
        }
Ejemplo n.º 20
0
        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));
        }
Ejemplo n.º 22
0
        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));
        }
Ejemplo n.º 23
0
        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"));
            }
        }
Ejemplo n.º 24
0
        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));
        }