예제 #1
0
        public async Task <IActionResult> Index()
        {
            ViewData[Constants.VIEW_DATA_PAGE_KEY] = Constants.VIEW_DATA_PAGE_ADIM_VALUE;

            // Retrieve knowledge base overview
            var srcDocs = await GetKnowledgeBaseSources();

            if (srcDocs == null)
            {
                return(RedirectToAction("Error", "Home", new { message = "Retrieved knowledge based overview failed" }));
            }

            KnowledgeBaseViewModel viewModel = new KnowledgeBaseViewModel();

            viewModel.SourceDocs.AddRange(srcDocs);

            var faqs = await GetKnowledgeBaseContents(false);

            if (faqs == null)
            {
                return(RedirectToAction("Error", "Home", new { message = "Retrieved knowledge based contents failed" }));
            }

            var filterFAQs = faqs.Where(e => e.Source == srcDocs.ElementAt(0));

            viewModel.FAQEntries.AddRange(filterFAQs);

            return(View(viewModel));
        }
예제 #2
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            KnowledgeBase knowledgeBase = db.KnowledgeBases.Find(id);

            if (knowledgeBase == null)
            {
                return(HttpNotFound());
            }
            KnowledgeBaseViewModel model = new KnowledgeBaseViewModel
            {
                Id                   = knowledgeBase.KnowledgeBaseId,
                Topic                = knowledgeBase.Topic,
                IncidentTitle        = knowledgeBase.IncidentTitle,
                IncidentDescription  = knowledgeBase.IncidentDescription,
                SolutionDescription  = knowledgeBase.SolutionDescription,
                EditedBy             = knowledgeBase.EditedBy,
                EditionDate          = knowledgeBase.EditionDate,
                KBAttachmentFilePath = knowledgeBase.KBAttachmentFilePath,
            };

            return(View(model));
        }
예제 #3
0
        public ActionResult Create(KnowledgeBaseViewModel model)
        {
            if (ModelState.IsValid)
            {
                var knowledgeBase = new KnowledgeBase
                {
                    KnowledgeBaseId     = model.Id,
                    Topic               = model.Topic,
                    IncidentTitle       = model.IncidentTitle,
                    IncidentDescription = model.IncidentDescription,
                    SolutionDescription = model.SolutionDescription,
                    CreationDate        = DateTime.Now,
                    CreatedBy           = User.Identity.GetUserId <int>(),
                    ITStaffId           = User.Identity.GetUserId <int>(),
                };

                if (model.KBAttachment != null && model.KBAttachment.ContentLength > 0)
                {
                    var extensions = new[] { "pdf", "docx", "doc", "jpeg", "png", "jpg" };

                    string filename = Path.GetFileName(model.KBAttachment.FileName);

                    string ext = Path.GetExtension(filename).Substring(1);

                    if (!extensions.Contains(ext, StringComparer.OrdinalIgnoreCase))
                    {
                        ModelState.AddModelError(string.Empty, "Accepted file are pdf, docx, doc, jpeg, jpg and png documents");
                        return(View());
                    }

                    string appFolder = "~/Content/Uploads/";

                    var rand = Guid.NewGuid().ToString();

                    string path = Path.Combine(Server.MapPath(appFolder), rand + "-" + filename);

                    model.KBAttachment.SaveAs(path);

                    knowledgeBase.KBAttachmentFilePath = appFolder + rand + "-" + filename;
                }
                db.KnowledgeBases.Add(knowledgeBase);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }
예제 #4
0
        /// <summary>
        /// This action lists the details of a specific Knowldge Base.
        /// </summary>
        /// <param name="id">Knowledge Base ID</param>
        /// <returns>Knowldge Base Details</returns>
        // GET: KnowledgeBase/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            KnowledgeBase knowledgeBase = db.KnowledgeBases.Find(id);

            if (knowledgeBase == null)
            {
                return(HttpNotFound());
            }

            string temp = null;

            if (!(knowledgeBase.EditedBy == null))
            {
                temp = db.ITStaffs.Find(knowledgeBase.EditedBy).FullName;
            }

            if (knowledgeBase.EditedBy == null)
            {
                temp = "";
            }

            var model = new KnowledgeBaseViewModel
            {
                Id                   = knowledgeBase.KnowledgeBaseId,
                CreatedByName        = knowledgeBase.ITStaff.FullName,
                EditedBy             = User.Identity.GetUserId <int>(),
                EditedByName         = temp,
                Topic                = knowledgeBase.Topic,
                IncidentTitle        = knowledgeBase.IncidentTitle,
                IncidentDescription  = knowledgeBase.IncidentDescription,
                SolutionDescription  = knowledgeBase.SolutionDescription,
                CreationDate         = knowledgeBase.CreationDate,
                EditionDate          = knowledgeBase.EditionDate,
                KBAttachmentFilePath = knowledgeBase.KBAttachmentFilePath,
            };

            return(View(model));
        }