Пример #1
0
        // GET: Knowledge/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var knowledge = await _context.Knowledged.FindAsync(id);

            if (knowledge == null)
            {
                return(NotFound());
            }

            KnowledgeViewModel vm_knowledge = new KnowledgeViewModel
            {
                Id               = knowledge.Id,
                CostYear         = knowledge.CostYear,
                PlanName         = knowledge.PlanName,
                NumberLaw        = knowledge.NumberLaw,
                DefiProjectClass = knowledge.DefiProjectClass,
                ExecutiveUnit    = knowledge.ExecutiveUnit,
                PlanHost         = knowledge.PlanHost,
                ProjectClass     = knowledge.ProjectClass,
                KeywordTw        = knowledge.KeywordTw,
                SummaryTw        = knowledge.SummaryTw,
                KeywordEng       = knowledge.KeywordEng,
                InfoLink         = knowledge.InfoLink
            };

            return(View(vm_knowledge));
        }
Пример #2
0
        // public async Task<IActionResult> Create([Bind("Id,CostYear,PlanName,NumberLaw,DefiProjectCalss,ExecutiveUnit,PlanHost,ProjectClass,KeywordTw,SummaryTw,KeywordEng,SummaryEng")] Knowledged knowledge)
        public async Task <IActionResult> Create(KnowledgeViewModel vm_knowledge)
        {
            if (ModelState.IsValid)
            {
                Knowledged knowledgeds = new Knowledged
                {
                    Id               = vm_knowledge.Id,
                    CostYear         = vm_knowledge.CostYear,
                    PlanName         = vm_knowledge.PlanName,
                    NumberLaw        = vm_knowledge.NumberLaw,
                    DefiProjectClass = vm_knowledge.DefiProjectClass,
                    ExecutiveUnit    = vm_knowledge.ExecutiveUnit,
                    PlanHost         = vm_knowledge.PlanHost,
                    ProjectClass     = vm_knowledge.ProjectClass,
                    KeywordTw        = vm_knowledge.KeywordTw,
                    SummaryTw        = vm_knowledge.SummaryTw,
                    KeywordEng       = vm_knowledge.KeywordEng,
                    InfoLink         = vm_knowledge.InfoLink
                };

                _context.Add(knowledgeds);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vm_knowledge));
        }
Пример #3
0
        public ActionResult Edit(KnowledgeViewModel model)
        {
            var knowledgeDTO = new KnowledgeDTO
            {
                Id          = model.Id,
                Name        = model.Name.Trim(),
                Description = model.Description,
                ParentId    = model.ParentId
            };

            knowledgeService.Update(knowledgeDTO);

            return(RedirectToAction("Index"));
        }
Пример #4
0
        public ActionResult AddArticle(int id, int?uid)
        {
            var model = new KnowledgeViewModel
            {
                CategoryId = id,
            };

            if (uid.HasValue)
            {
                var k = db.Questions.SingleOrDefault(m => m.Id == uid);
                model.Question  = k.Content;
                model.PendingId = uid.Value;
                model.Answer    = db.Answers.FirstOrDefault(m => m.QuestionId == uid && m.Accepted).Content;
            }
            ViewBag.Category    = db.Categories.SingleOrDefault(m => m.Id == id).Name;
            ViewBag.Breadcrumbs = setBreadcrumbs(id);
            return(View(model));
        }
Пример #5
0
        //public async Task<IActionResult> Edit(int id, [Bind("Id,CostYear,PlanName,NumberLaw,DefiProjectCalss,ExecutiveUnit,PlanHost,ProjectClass,KeywordTw,SummaryTw,KeywordEng,SummaryEng")] Knowledged knowledge)
        public async Task <IActionResult> Edit(int id, KnowledgeViewModel vm_knowledge)
        {
            if (id != vm_knowledge.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Knowledged knowledgeds = new Knowledged
                    {
                        Id               = vm_knowledge.Id,
                        CostYear         = vm_knowledge.CostYear,
                        PlanName         = vm_knowledge.PlanName,
                        NumberLaw        = vm_knowledge.NumberLaw,
                        DefiProjectClass = vm_knowledge.DefiProjectClass,
                        ExecutiveUnit    = vm_knowledge.ExecutiveUnit,
                        PlanHost         = vm_knowledge.PlanHost,
                        ProjectClass     = vm_knowledge.ProjectClass,
                        KeywordTw        = vm_knowledge.KeywordTw,
                        SummaryTw        = vm_knowledge.SummaryTw,
                        KeywordEng       = vm_knowledge.KeywordEng,
                        InfoLink         = vm_knowledge.InfoLink
                    };
                    _context.Update(knowledgeds);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!KnowledgeExists(vm_knowledge.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vm_knowledge));
        }
Пример #6
0
        public ActionResult Create(KnowledgeViewModel model)
        {
            if (model != null)
            {
                var knowledgeDTO = new KnowledgeDTO
                {
                    Name        = model.Name,
                    Description = model.Description,
                    ParentId    = model.ParentId
                };

                knowledgeService.Create(knowledgeDTO);

                ModelState.Clear();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public static List <KnowledgeViewModel> AreaofKnowledge()
        {
            List <KnowledgeViewModel> knowledgeViewModels = new List <KnowledgeViewModel>();

            var ast = cntxt.Questions.Select(u => new { u.LanguageId, u.CertificationId, u.KnowledgeAreaId, u.KnowledgeArea.Certification.CertificationName, u.KnowledgeArea.KnowledgeAreaName, u.LanguageMaster.LanguageName }).Distinct();


            foreach (var element in ast)
            {
                KnowledgeViewModel knwledgemdl = new KnowledgeViewModel();

                knwledgemdl.CertificationId   = element.CertificationId;
                knwledgemdl.KnowledgeAreaId   = element.KnowledgeAreaId;
                knwledgemdl.KnowledgeAreaName = element.KnowledgeAreaName;
                knwledgemdl.LanguageName      = element.LanguageName;

                knowledgeViewModels.Add(knwledgemdl);
            }


            return(knowledgeViewModels);
        }
Пример #8
0
        public JsonResult ViewKnowedge(int id)
        {
            var r = db.Knowledges.SingleOrDefault(m => m.Id == id);

            if (r != null)
            {
                r.Hits++;
                db.SaveChanges();
                var model = new KnowledgeViewModel
                {
                    Id         = r.Id,
                    Question   = r.Topic,
                    Answer     = r.Content,
                    Keywords   = r.Keywords,
                    CategoryId = r.CategoryId.Value,
                    Attachment = r.Attachment,
                };
                return(Json(model, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("找不到知识条目", JsonRequestBehavior.AllowGet));
            }
        }
Пример #9
0
        public ActionResult EditArticle(int id, KnowledgeViewModel model)
        {
            if (ModelState.IsValid)
            {
                ViewBag.Categories = getCategories();

                var c = db.Knowledges.SingleOrDefault(m => m.Id == model.Id);

                //Check and save attachment,
                HttpRequestBase request = this.Request;
                if (request.Files.Count == 1 && !string.IsNullOrWhiteSpace(request.Files[0].FileName))
                {
                    //Check and delete old attachment first
                    if (!string.IsNullOrEmpty(c.Attachment))
                    {
                        try
                        {
                            string   path = System.Web.HttpContext.Current.Server.MapPath("~" + c.Attachment);
                            FileInfo f    = new FileInfo(path);
                            if (f.Exists)
                            {
                                f.Delete();
                            }
                        }
                        catch (Exception) { }
                    }
                    //Save new attachment
                    string originalName = (new FileInfo(request.Files[0].FileName)).Name;
                    string fileName     = DateTime.Now.ToString("yyyyMMddHHmmss") + "" + originalName.Substring(originalName.LastIndexOf("."));
                    string dir          = System.Web.HttpContext.Current.Server.MapPath("~/" + Constants.UploadFolder + DateTime.Now.ToString("yyyyMM"));
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                    request.Files[0].SaveAs(Path.Combine(dir, fileName));
                    c.Attachment = Constants.UploadFolder + DateTime.Now.ToString("yyyyMM") + "/" + fileName;
                }
                c.Topic    = model.Question.Trim();
                c.Content  = model.Answer.Trim();
                c.Keywords = model.Keywords.Trim();
                int newCId = int.Parse(Request.Form["NewCategoryId"]);
                if (newCId > 0 && newCId != c.CategoryId)
                {
                    c.CategoryId = newCId;
                }
                db.SaveChanges();

                ViewBag.SuccessMessage = "知识修改成功!";
                Log("修改知识");
                //Check and add hot words.
                var keys = model.Keywords.Trim().Split(new char[1] {
                    ' '
                });
                foreach (var k in keys)
                {
                    if (!String.IsNullOrWhiteSpace(k))
                    {
                        int t = db.HotWords.Count(m => m.KeyWord == k);
                        if (t <= 0)
                        {
                            db.HotWords.Add(new HotWord
                            {
                                KeyWord   = k,
                                CreatedAt = DateTime.Now,
                                Hits      = 0,
                                CreatedBy = CurrentUser.Id,
                            });
                        }
                    }
                    db.SaveChanges();
                }
            }
            var newModel = from row in db.Knowledges
                           where row.Id == id
                           select new KnowledgeViewModel
            {
                Id         = row.Id,
                Question   = row.Topic,
                Answer     = row.Content,
                CategoryId = row.CategoryId.Value,
                Keywords   = row.Keywords,
                Hits       = row.Hits.Value,
                CreatedAt  = row.CreatedAt,
                CreatedBy  = row.User.RealName,
                Attachment = row.Attachment,
            };

            ViewBag.Breadcrumbs = setBreadcrumbs(newModel.SingleOrDefault().CategoryId);
            return(View(newModel.SingleOrDefault()));
        }
Пример #10
0
        public ActionResult AddArticle(KnowledgeViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.Question = model.Question.Trim();
                var i = db.Knowledges.Count(m => m.Topic.Equals(model.Question, StringComparison.OrdinalIgnoreCase) && m.CategoryId == model.CategoryId);
                if (i > 0)
                {
                    ModelState.AddModelError("", "同类别下相同知识条目已经存在,请勿重复添加!");
                }
                else
                {
                    var attachmentPath = "";
                    //upload file
                    HttpRequestBase request = this.Request;
                    if (request.Files.Count == 1 && !string.IsNullOrWhiteSpace(request.Files[0].FileName))
                    {
                        string originalName = (new FileInfo(request.Files[0].FileName)).Name;
                        string fileName     = DateTime.Now.ToString("yyyyMMddHHmmss") + "" + originalName.Substring(originalName.LastIndexOf("."));
                        string dir          = System.Web.HttpContext.Current.Server.MapPath("~/" + Constants.UploadFolder + DateTime.Now.ToString("yyyyMM"));
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }
                        attachmentPath = Path.Combine(dir, fileName);
                        request.Files[0].SaveAs(attachmentPath);
                        attachmentPath = Constants.UploadFolder + DateTime.Now.ToString("yyyyMM") + "/" + fileName;
                    }

                    db.Knowledges.Add(new Knowledge
                    {
                        Topic      = model.Question,
                        Content    = model.Answer,
                        Keywords   = model.Keywords,
                        Hits       = 0,
                        CreatedAt  = DateTime.Now,
                        CreatedBy  = CurrentUser.Id,
                        CategoryId = model.CategoryId,
                        Attachment = attachmentPath
                    });

                    //If it's pending Question remove it

                    /*
                     * if (model.PendingId > 0)
                     * {
                     *  var p = db.Questions.SingleOrDefault(m => m.Id == model.PendingId);
                     *  if (p != null)
                     *      db.Questions.Remove(p);
                     * }
                     */


                    //Check and add hot words.
                    var keys = model.Keywords.Trim().Split(new char[1] {
                        ' '
                    });
                    foreach (var k in keys)
                    {
                        if (!String.IsNullOrWhiteSpace(k))
                        {
                            int t = db.HotWords.Count(m => m.KeyWord == k);
                            if (t <= 0)
                            {
                                db.HotWords.Add(new HotWord
                                {
                                    KeyWord   = k,
                                    CreatedAt = DateTime.Now,
                                    Hits      = 0,
                                    CreatedBy = CurrentUser.Id,
                                });
                            }
                        }
                    }
                    CurrentUser.Score += Constants.UserScore.AddKnowedgeScore;
                    db.SaveChanges();
                    ViewBag.SuccessMessage = "知识添加成功!";
                    Log("添加知识");
                }
            }

            ViewBag.Category    = db.Categories.SingleOrDefault(m => m.Id == model.CategoryId).Name;
            ViewBag.Breadcrumbs = setBreadcrumbs(model.CategoryId);
            return(View(model));
        }