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)); } } } }
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); } }
// 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()); } }
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)); }
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; }
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; }
// 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()); } }
public void Update(KnowledgeVM request) { var updateCommand = mapper.Map <UpdateKnowledgeCommand>(request); bus.SendCommand(updateCommand); }