//--------------------------------------------------------------------------------------- // Update project //--------------------------------------------------------------------------------------- /// <summary> /// Update project in database /// </summary> /// <param name="project"></param> /// <param name="listSkillOfProjectsId"></param> /// <param name="isSkillSelected"></param> public void addOrUpdateSkillWithObjects(ProjectsViewModel project, IEnumerable<string> listSkillOfProjectsId, IEnumerable<string> isSkillSelected) { // Project Skills handling List<int> listAddedSkillsId = new List<int>(); if (isSkillSelected != null) { int id; SkillsViewModel newSkill; for (int i = 0; i < isSkillSelected.Count(); i++) { string isSelected = isSkillSelected.ElementAt(i).Split('-').ToList()[0]; string isSelectedId = isSkillSelected.ElementAt(i).Split('-').ToList()[1]; id = Int32.Parse(isSelectedId); newSkill = db.Skills.Where(y => y.ID == id).Include("CategoryViewModel").Include("LevelsViewModel").DefaultIfEmpty().Single(); if (isSelected == "true") { project.Skills.Add(newSkill); listAddedSkillsId.Add(id); } } } // removing uncheck Projects skills if (listSkillOfProjectsId != null) { foreach (var skillIdString in listSkillOfProjectsId) { var skillId = Int32.Parse(skillIdString); if ((listAddedSkillsId != null && !listAddedSkillsId.Contains(skillId)) || listAddedSkillsId == null) { var skillToRemove = db.Skills.Where(x => x.ID == skillId).Include("CategoryViewModel").Include("LevelsViewModel").First(); project.Skills.Remove(skillToRemove); } } } }
public ActionResult Details(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } ProjectsViewModel projectsViewModel = new ProjectsViewModel(); try { projectsViewModel = db.Projects.Where(x => x.ID == id).Include(x => x.ProjectDetail).Include(x => x.ProjectDetail.Pictures).SingleOrDefault(); var pictures = db.PicturesApp.Include(x => x.ProjectDetail).Where(x => x.ProjectDetail.ID == projectsViewModel.ProjectDetail.ID).ToList(); projectsViewModel.ProjectDetail.Pictures = pictures; } catch (Exception ex) { Log.write(ex.Message, "WAR"); return RedirectToAction("Index"); } if (projectsViewModel == null) { return HttpNotFound(); } return View(projectsViewModel); }
/// <summary> /// Save project from form into database /// </summary> /// <param name="formDataDictionary"></param> /// <param name="outputProjectModel"></param> public void populateDBWithDataFromForm(Dictionary<string, object> formDataDictionary, ProjectsViewModel outputProjectModel) { var id = Int32.Parse((string)formDataDictionary["projectDetailID"]); addOrUpdateSkillWithObjects(((ProjectsViewModel)formDataDictionary["projectsViewModel"]), (IEnumerable<string>)formDataDictionary["listSkillOfProjectsId"], (IEnumerable<string>)formDataDictionary["isSkillSelected"]); outputProjectModel.link = ((ProjectsViewModel)formDataDictionary["projectsViewModel"]).link; outputProjectModel.Resume = ((ProjectsViewModel)formDataDictionary["projectsViewModel"]).Resume; outputProjectModel.Title = ((ProjectsViewModel)formDataDictionary["projectsViewModel"]).Title; outputProjectModel.Skills = ((ProjectsViewModel)formDataDictionary["projectsViewModel"]).Skills; //ProjectDetailsViewModel newProjectDetail = new ProjectDetailsViewModel(); outputProjectModel.ProjectDetail.Subject = ((ProjectsViewModel)formDataDictionary["projectsViewModel"]).ProjectDetail.Subject; outputProjectModel.ProjectDetail.Status = ((ProjectsViewModel)formDataDictionary["projectsViewModel"]).ProjectDetail.Status; outputProjectModel.ProjectDetail.Description = ((ProjectsViewModel)formDataDictionary["projectsViewModel"]).ProjectDetail.Description; outputProjectModel.ProjectDetail.Date = ((ProjectsViewModel)formDataDictionary["projectsViewModel"]).ProjectDetail.Date; outputProjectModel.ProjectDetail.Client = ((ProjectsViewModel)formDataDictionary["projectsViewModel"]).ProjectDetail.Client; //outputProjectModel.ProjectDetail = newProjectDetail; }
// GET: Projects/Create public ActionResult Create() { var project = new ProjectsViewModel(); project.Skills = db.Skills.ToList(); return View(project); }
// GET: Projects/Delete/5 public ActionResult Delete(int? id) { ProjectsViewModel projectsViewModel = new ProjectsViewModel(); try { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } projectsViewModel = db.Projects.Find(id); if (projectsViewModel == null) { return HttpNotFound(); } } catch (Exception ex) { Log.write(ex.Message, "ERR"); } return View(projectsViewModel); }