コード例 #1
0
        public void UpdateKnowledgeDesigner(string[] selectedDesigner, KnowledgeVM knowledgeToUpdate)
        {
            if (knowledgeToUpdate.KnowledgeDesigner == null)
            {
                knowledgeToUpdate.KnowledgeDesigner = new List <KnowledgeDesignerVM>();
            }

            var all = designerRepository.GetAll();
            var selectedDesignerHS = new HashSet <string>(selectedDesigner);
            var knowledgeDesigner  = new HashSet <int>(knowledgeToUpdate.KnowledgeDesigner.Select(c => c.Designer.Id));

            knowledgeDesignerRepository.RemoveAll(knowledgeToUpdate.Id);
            foreach (var designer in all)
            {
                if (selectedDesignerHS.Contains(designer.Id.ToString()))
                {
                    if (!knowledgeDesigner.Contains(designer.Id))
                    {
                        knowledgeToUpdate.KnowledgeDesigner.Add(new KnowledgeDesignerVM {
                            KnowledgeId = knowledgeToUpdate.Id, DesignerId = designer.Id
                        });
                    }
                }
                else
                {
                    if (knowledgeDesigner.Contains(designer.Id))
                    {
                        var knowledgeToRemove = knowledgeToUpdate.KnowledgeDesigner.SingleOrDefault(i => i.DesignerId == designer.Id);
                        knowledgeDesignerRepository.Remove(mapper.Map <KnowledgeDesigner>(knowledgeToRemove));
                    }
                }
            }
        }
コード例 #2
0
 public void Register(KnowledgeVM request)
 {
     if (request.Id == 0)
     {
         var command = mapper.Map <RegisterNewKnowledgeCommand>(request);
         bus.SendCommand(command);
     }
     else
     {
         var command = mapper.Map <UpdateKnowledgeCommand>(request);
         bus.SendCommand(command);
     }
 }
コード例 #3
0
        // PUT api/Knowledges/5
        public IHttpActionResult Put(int id, [FromBody] KnowledgeVM value)
        {
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <KnowledgeVM, KnowledgeDTO>()).CreateMapper();

            try
            {
                db.Update(id, mapper.Map <KnowledgeVM, KnowledgeDTO>(value));
                return(Ok());
            }
            catch (ValidationException)
            {
                return(NotFound());
            }
        }
コード例 #4
0
        public async Task <IActionResult> KnowledgeAsync([Bind("People, PeopleId, KnowledgeDesigner, KnowledgeDeveloper, Id")] KnowledgeVM request, string[] selectDeveloper, string[] selectDesigner)
        {
            knowledgeService.UpdateKnowledgeDesigner(selectDesigner, request);
            knowledgeService.UpdateKnowledgeDeveloper(selectDeveloper, request);

            var people = await peopleService.GetByEmailAsync(User.Identity.Name);

            people.Knowledge = request;
            knowledgeService.Register(request);

            PopulateAssignedDeveloperData(people.Knowledge);
            PopulateAssignedDesignerData(people.Knowledge);

            return(RedirectToAction("KnowledgeAsync", people.Id));
        }
コード例 #5
0
        private void PopulateAssignedKnowledgeDesignerData(KnowledgeVM knowledge)
        {
            var all          = designerService.GetAll();
            var knowledgeDes = new HashSet <int>(knowledge.KnowledgeDesigner.Select(c => c.DesignerId));
            var viewModel    = new List <SelectedItems>();

            foreach (var item in all)
            {
                viewModel.Add(new SelectedItems
                {
                    Id            = item.Id,
                    DescriptionEN = item.DescriptionEN,
                    DescriptionPT = item.DescriptionPT,
                    Assigned      = knowledgeDes.Contains(item.Id)
                });
            }

            ViewData["Designers"] = viewModel;
        }
コード例 #6
0
        private void PopulateAssignedDesignerData(KnowledgeVM knowledge)
        {
            var all          = designerService.GetAll();
            var knowledgeDes = new HashSet <int>(knowledge.KnowledgeDesigner.Select(c => c.DesignerId));
            var viewModel    = new List <SelectedItemWithValue>();

            foreach (var item in all)
            {
                viewModel.Add(new SelectedItemWithValue("selectDesigner")
                {
                    Id            = item.Id,
                    DescriptionEN = item.DescriptionEN,
                    DescriptionPT = item.DescriptionPT,
                    Value         = "1"
                });
            }

            ViewData["Designer"] = viewModel;
        }
コード例 #7
0
        // POST api/Knowledges
        public IHttpActionResult Post([FromBody] KnowledgeVM value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <KnowledgeVM, KnowledgeDTO>()).CreateMapper();

            try
            {
                db.Create(mapper.Map <KnowledgeVM, KnowledgeDTO>(value));
                return(StatusCode(HttpStatusCode.Created));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
コード例 #8
0
        public void Update(KnowledgeVM request)
        {
            var updateCommand = mapper.Map <UpdateKnowledgeCommand>(request);

            bus.SendCommand(updateCommand);
        }