示例#1
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"));
        }
示例#2
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));
        }
示例#3
0
        public void Update(int id, KnowledgeDTO item)
        {
            if (item == null)
            {
                throw new ValidationException("Item is undefined", "");
            }

            var itemToUpdate = Database.Knowledges.Get(id);

            if (itemToUpdate == null)
            {
                throw new ValidationException("Knowledge is not found", "");
            }

            itemToUpdate.Name   = item.Name;
            itemToUpdate.AreaId = item.AreaId;
            itemToUpdate.Area   = Database.Areas.Get(item.AreaId);

            Database.Knowledges.Update(itemToUpdate);
            Database.Save();
        }
示例#4
0
        public void Create(KnowledgeDTO item)
        {
            if (item == null)
            {
                throw new ValidationException("Item is undefined", "");
            }

            var sameItemFromDb = Database.Knowledges.Find(
                x => x.Name == item.Name &&
                x.AreaId == item.AreaId).FirstOrDefault();

            if (sameItemFromDb != null)
            {
                throw new ValidationException("The same item is already exist", "");
            }

            var mapper    = new MapperConfiguration(cfg => cfg.CreateMap <KnowledgeDTO, Knowledge>()).CreateMapper();
            var knowledge = mapper.Map <KnowledgeDTO, Knowledge>(item);

            Database.Knowledges.Create(knowledge);
            Database.Save();
        }