コード例 #1
0
        public ActionResult EditSkills(string serializedModel, int id, FormCollection form)
        {
            skill   skillDomain             = new skill();
            project projectDomain           = projectService.GetById(id);
            List <SkillViewModel> listSkill = JsonConvert.DeserializeObject <List <SkillViewModel> >(serializedModel);

            ViewBag.TAGS = listSkill;
            //First delete after add
            foreach (var skill in listSkill)
            {
                //Delete
                projectskill projectSkillDomainDelete = projectSkillService.GetMany().Where(a => a.idProject == id)
                                                        .Where(b => b.idSkill == skill.IdSkill).FirstOrDefault();
                if (projectSkillDomainDelete != null)
                {
                    projectSkillService.Delete(projectSkillDomainDelete);
                    projectSkillService.Commit();
                }
                //Add
                skillDomain.IdSkill = skill.IdSkill;
                projectskill projectSkillDomain = new projectskill();
                projectSkillDomain.idSkill    = skillDomain.IdSkill;
                projectSkillDomain.idProject  = projectDomain.id;
                projectSkillDomain.percentage = Int32.Parse(form.Get(skill.NameSkill));
                projectSkillService.Add(projectSkillDomain);
                projectSkillService.Commit();
            }
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public ActionResult EditSkills(string serializedModel, int id, FormCollection form, string percent)
        {
            List <SkillViewModel> listSkill = JsonConvert.DeserializeObject <List <SkillViewModel> >(serializedModel);

            ViewBag.TAGS = listSkill;
            projectskill projectSkill           = new projectskill();
            List <ProjectSkillViewModel> listPS = new List <ProjectSkillViewModel>();

            foreach (var skill in listSkill)
            {
                projectSkill = projectSkillService.GetMany().Where(a => a.idProject == id)
                               .Where(b => b.idSkill == skill.IdSkill).FirstOrDefault();
                if (projectSkill != null)
                {
                    listPS.Add(new ProjectSkillViewModel(projectSkill.idProject, projectSkill.idSkill, projectSkill.percentage));
                }
            }
            ViewBag.ProjectSkills = listPS;
            return(View("EditSkills"));
        }
コード例 #3
0
        public ActionResult Skills(string serializedModel, int id, FormCollection form)
        {
            skill   skillDomain             = new skill();
            project projectDomain           = projectService.GetById(id);
            List <SkillViewModel> listSkill = JsonConvert.DeserializeObject <List <SkillViewModel> >(serializedModel);

            ViewBag.TAGS = listSkill;

            foreach (var skill in listSkill)
            {
                skillDomain.IdSkill = skill.IdSkill;
                projectskill projectSkillDomain = new projectskill
                {
                    idSkill    = skillDomain.IdSkill,
                    idProject  = projectDomain.id,
                    percentage = Int32.Parse(form.Get("percent+" + skill.IdSkill))
                };
                projectSkillService.Add(projectSkillDomain);
                projectSkillService.Commit();
            }
            return(View());
        }
コード例 #4
0
        public ActionResult Edit(ProjectViewModel projectViewModel, string tags, string btn)
        {
            if (btn != null && btn == "Next Step")
            {
                using (var client = new HttpClient())
                {
                    String clientId    = Request.Form["CLIENT"].ToString();
                    string projectType = Request.Form["TypeProject"].ToString();
                    projectViewModel.projectType = projectType;
                    person person = clientService.GetById(Int32.Parse(clientId));
                    projectViewModel.clientId = person;
                    client.BaseAddress        = new Uri("http://127.0.0.1:18080/");
                    var putTask =
                        client.PutAsJsonAsync <ProjectViewModel>("Map-JavaEE-web/MAP/projects", projectViewModel);
                    putTask.Wait();
                    var result = putTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index"));
                    }
                }
                FillEnumDropDownList();
                ViewBag.CLIENT = new SelectList(db.people, "id", "nameSociety", projectViewModel.clientId.id);

                //list value of tags from view
                List <string> listTagsFromView = tags.Split(',').ToList();
                //list of skills of project from db
                List <skill> listSkillsFromDb = new List <skill>();
                //List qui sera envoyer à la vue EditSkills avec liste des skills ajouter
                List <SkillViewModel> listSkillViewModel = new List <SkillViewModel>();

                skill        skillDomain  = new skill();
                projectskill projectSkill = new projectskill();
                var          res          = db.projectskills
                                            .Join(db.skills, ps => ps.idSkill, s => s.IdSkill, (ps, s) => new { ps, s })
                                            .Join(db.projects, ppc => ppc.ps.idProject, p => p.id, (ppc, p) => new { ppc, p })
                                            .Where(m => m.p.id.Equals(projectViewModel.id))
                                            .Select(m => new
                {
                    id      = m.ppc.s.IdSkill,
                    name    = m.ppc.s.NameSkill,
                    percent = m.ppc.ps.percentage
                }).ToList();

                foreach (var item in res)
                {
                    listSkillsFromDb.Add(new skill(item.id, item.name));
                }

                List <string> nameSkills = listSkillsFromDb.Select(o => o.NameSkill).ToList();

                foreach (var tag in listTagsFromView)
                {
                    if (!(nameSkills.Contains(tag)))
                    {
                        skillDomain.NameSkill = tag;
                        skillService.Add(skillDomain);
                        skillService.Commit();
                        listSkillViewModel.Add(new SkillViewModel(skillDomain.IdSkill, skillDomain.NameSkill));
                    }
                }
                foreach (var skill in listSkillsFromDb)
                {
                    if (!(listTagsFromView.Contains(skill.NameSkill)))
                    {
                        projectSkill = projectSkillService.GetMany().Where(a => a.idProject == projectViewModel.id)
                                       .Where(b => b.idSkill == skill.IdSkill).FirstOrDefault();
                        projectSkillService.Delete(projectSkill);

                        projectSkillService.Commit();

                        skillDomain = skillService.GetById(skill.IdSkill);
                        skillService.Delete(skillDomain);

                        skillService.Commit();
                    }
                    else
                    {
                        listSkillViewModel.Add(new SkillViewModel(skill.IdSkill, skill.NameSkill));
                    }
                }

                return(RedirectToAction("EditSkills", new { serializedModel = JsonConvert.SerializeObject(listSkillViewModel), id = projectViewModel.id }));
            }
            return(View(projectViewModel));
        }