public async Task <IActionResult> AddProjectMemberParticipant(EditProjectDetailViewModel model) { if (ModelState.IsValid) { try{ var ProjectId = model.ProjectID; var project = await _context.Projects.SingleOrDefaultAsync(m => m.ID == ProjectId); var MemberId = model.SelectedID; var member = await _context.Members.SingleOrDefaultAsync(m => m.ID == MemberId); ProjectRoster participant = new ProjectRoster { ProjectID = ProjectId, Project = project, ProjectParticipantID = MemberId, ProjectParticipant = member }; _context.ProjectRoster.Add(participant); _context.SaveChanges(); } catch (Exception exp) { throw(exp); } return(RedirectToAction(nameof(Details), new { id = model.ProjectID })); } return(View()); }
public async Task <IActionResult> DeleteConfirmed(EditProjectDetailViewModel EPDVMD) { var projectAddedTo = await _context.Projects.SingleOrDefaultAsync(Pro => Pro.ID == EPDVMD.ProjectID); var participantToAdd = await _context.Members.SingleOrDefaultAsync(Mem => Mem.ID == EPDVMD.SelectedID); var projectAddedToId = await _context.ProjectRoster.SingleOrDefaultAsync(Pro => Pro.ProjectID == EPDVMD.ProjectID); ProjectRoster chick = new ProjectRoster { ProjectID = projectAddedTo.ID, Project = projectAddedTo, ProjectParticipantID = participantToAdd.ID, ProjectParticipant = participantToAdd }; //this writes a new record to the database _context.ProjectRoster.Attach(chick); _context.ProjectRoster.Remove(chick); // _context.Projects.Remove(projectAddedTo); // _context.ProjectRoster.Remove(projectAddedToId); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> AddConfirmed(EditProjectDetailViewModel EPDVMD) { var projectAddedTo = await _context.Projects.SingleOrDefaultAsync(Pro => Pro.ID == EPDVMD.ProjectID); //change the Members to Clients to add clients and switch back to add Members var participantToAdd = await _context.Members.SingleOrDefaultAsync(Mem => Mem.ID == EPDVMD.SelectedID); // var clientToAdd = await _context.Clients.SingleOrDefaultAsync(Cli => Cli.ID == EPDVMD.SelectedID); ProjectRoster dude = new ProjectRoster { ProjectID = projectAddedTo.ID, Project = projectAddedTo, ProjectParticipantID = participantToAdd.ID, ProjectParticipant = participantToAdd /* * ClientID = clientToAdd.ID, * Client = clientToAdd */ }; //this writes a new record to the database await _context.ProjectRoster.AddAsync(dude); //this saves the change from the write above await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public void UpdateProject(EditProjectDetailViewModel pvm) { var Config = new MapperConfiguration(cfg => { cfg.CreateMap <EditProjectDetailViewModel, Projects>(); }); IMapper mapper = Config.CreateMapper(); Projects projects = mapper.Map <EditProjectDetailViewModel, Projects>(pvm); pr.UpdateProject(projects); }
public ActionResult Edit(EditProjectDetailViewModel pvm) { pvm.AdminID = Convert.ToInt32(Session["CurrentUserID"]); pvm.DateOfStart = DateTime.Now; if (pvm.Attachments != null) { if (Request.Files.Count >= 1) { var File = Request.Files[0]; var ImgByte = new Byte[File.ContentLength - 1]; File.InputStream.Read(ImgByte, 0, ImgByte.Length); var Base64String = Convert.ToBase64String(ImgByte, 0, ImgByte.Length); pvm.Attachments = Base64String; } } this.ps.UpdateProject(pvm); return RedirectToAction("Index", "Home", new { area = "Admin" }); }
public async Task <IActionResult> AddConfirmed(EditProjectDetailViewModel EPDVMD) { var projectAddedTo = await _context.Projects.SingleOrDefaultAsync(Pro => Pro.ID == EPDVMD.ProjectID); var participantToAdd = await _context.Members.SingleOrDefaultAsync(Mem => Mem.ID == EPDVMD.SelectedID); var clientToAdd = await _context.Clients.SingleOrDefaultAsync(Clen => Clen.ID == EPDVMD.SelectedID); ProjectRoster thing = new ProjectRoster { ProjectID = projectAddedTo.ID, Project = projectAddedTo, ProjectParticipantID = participantToAdd.ID, ProjectParticipant = participantToAdd }; //this writes a new record to the database await _context.ProjectRoster.AddAsync(thing); //this saves the change from the write above await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); //attempt to add client to project, failed. // ProjectRoster anotherThing = new ProjectRoster // { // ProjectID = projectAddedTo.ID, // Project = projectAddedTo, // ProjectParticipantID = clientToAdd.ID, // ProjectParticipant = clientToAdd // }; // //this writes a new record to the database // await _context.ProjectRoster.AddAsync(anotherThing); // //this saves the change from the write above // await _context.SaveChangesAsync(); // return RedirectToAction(nameof(Index)); }
public async Task <IActionResult> EditProjectParticipants(String id, EditProjectDetailViewModel model) { var membersFromDb = _context.Members.ToList(); Member ans = null; foreach (var items in membersFromDb) { if (items.ID == model.SelectedID) { ans = items; } } var projectroster = new ProjectRoster { ProjectID = model.TheProject.ID.ToString(), Project = model.TheProject, ProjectParticipantID = model.SelectedID.ToString(), ProjectParticipant = ans }; _context.ProjectRoster.Add(projectroster); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
// GET: Projects/EditProjectParticipants/5 public async Task <IActionResult> EditProjectParticipants(string id) { if (id == null) { return(NotFound()); } var project = await _context.Projects.SingleOrDefaultAsync(m => m.ID == id); if (project == null) { return(NotFound()); } //var clients = await _context.Clients.ToListAsync(); //CLIENTS //pull 'em into lists first var clients = await _context.Clients.ToListAsync(); var projectroster = await _context.ProjectRoster.ToListAsync(); var uniqueclients = from participant in clients join projectparticipant in projectroster on participant.ID equals projectparticipant.ProjectParticipantID where participant.ID != projectparticipant.ProjectParticipantID select participant; List <SelectListItem> clientsSelectList = new List <SelectListItem>(); foreach (var client in clients) { clientsSelectList.Add(new SelectListItem { Value = client.ID, Text = client.FirstName + " " + client.LastName }); } var membersOnProject = from participant in _context.Members join projectparticipant in _context.ProjectRoster on participant.ID equals projectparticipant.ProjectParticipantID where project.ID == projectparticipant.ProjectID select participant; var allMembers = from participant in _context.Members select participant; var allMembersList = allMembers.ToList(); var membersOnProjectList = membersOnProject.ToList(); var membersNotOnProject = allMembersList.Except(membersOnProjectList).ToList(); List <SelectListItem> membersSelectList = new List <SelectListItem>(); foreach (var member in membersNotOnProject) { membersSelectList.Add(new SelectListItem { Value = member.ID, Text = member.FirstName + " " + member.LastName }); } //create and prepare ViewModel EditProjectDetailViewModel epdvm = new EditProjectDetailViewModel { ProjectID = project.ID, TheProject = project, ProjectClientsList = clientsSelectList, ProjectMembersList = membersSelectList }; // SelectedDropDown SDD = new SelectedDropDown // { // TheProject = project, // ProjectClientsList = clientsSelectList, // ProjectMembersList = membersSelectList // }; return(View(epdvm)); }
// GET: Projects/EditProjectParticipants/5 public async Task <IActionResult> EditProjectParticipants(string id) { if (id == null) { return(NotFound()); } var project = await _context.Projects.SingleOrDefaultAsync(m => m.ID == id); if (project == null) { return(NotFound()); } //var clients = await _context.Clients.ToListAsync(); //CLIENTS //pull 'em into lists first var clients = await _context.Clients.ToListAsync(); var projectroster = await _context.ProjectRoster.ToListAsync(); /* * var uniqueclients = * from participant in clients * join projectparticipant in projectroster * on participant.ID equals projectparticipant.ProjectParticipantID * where participant.ID != projectparticipant.ProjectParticipantID * select participant; */ var allClients = from participant in _context.Clients select participant; var clientsOnProject = from participant in _context.Clients join projectparticipant in _context.ProjectRoster on participant.ID equals projectparticipant.ProjectParticipantID where project.ID == projectparticipant.ProjectID select participant; var allClientsInProject = allClients.ToList(); var specificClientOnProjects = clientsOnProject.ToList(); var allClientsNotOnProject = allClientsInProject.Except(specificClientOnProjects).ToList(); List <SelectListItem> clientsSelectList = new List <SelectListItem>(); foreach (var client in allClientsNotOnProject) { clientsSelectList.Add(new SelectListItem { Value = client.ID, Text = client.FirstName + " " + client.LastName }); } //MEMBERS //pull 'em into lists first var members = await _context.Members.ToListAsync(); // var uniquemembers = // from participant in members // join projectparticipant in projectroster // on participant.ID equals projectparticipant.ProjectParticipantID // where participant.ID != projectparticipant.ProjectParticipantID // select participant; //var UniqueMembers = await _context.Members.ToListAsync(); var membersOnProject = from participant in _context.Members join projectparticipant in _context.ProjectRoster on participant.ID equals projectparticipant.ProjectParticipantID where project.ID == projectparticipant.ProjectID select participant; //all members on project var allMembers = from participant in _context.Members select participant; //all members in db var allMembersProject = allMembers.ToList(); var specificMembersOnProjects = membersOnProject.ToList(); var allMembersNotOnProject = allMembersProject.Except(specificMembersOnProjects).ToList(); List <SelectListItem> membersSelectList = new List <SelectListItem>(); //drop down foreach (var member in allMembersNotOnProject) { membersSelectList.Add(new SelectListItem { Value = member.ID, Text = member.FirstName + " " + member.LastName }); } //string result = Request.Form["Model.ProjectMemberList"].ToString(); //create and prepare ViewModel EditProjectDetailViewModel epdvm = new EditProjectDetailViewModel { TheProject = project, ProjectClientsList = clientsSelectList, ProjectMembersList = membersSelectList //MembersNotOnProject = allMembersNotOnProject }; return(View(epdvm)); }
// GET: Projects/EditProjectParticipants/5 public async Task <IActionResult> EditProjectParticipants(string id) { if (id == null) { return(NotFound()); } var project = await _context.Projects.SingleOrDefaultAsync(m => m.ID == id); if (project == null) { return(NotFound()); } //var clients = await _context.Clients.ToListAsync(); //CLIENTS //pull 'em into lists first var clients = await _context.Clients.ToListAsync(); var projectroster = await _context.ProjectRoster.ToListAsync(); /* * var uniqueclients = * from participant in clients * join projectparticipant in projectroster * on participant.ID equals projectparticipant.ProjectParticipantID * where participant.ID != projectparticipant.ProjectParticipantID * select participant; */ List <SelectListItem> clientsSelectList = new List <SelectListItem>(); foreach (var client in clients) { clientsSelectList.Add(new SelectListItem { Value = client.ID, Text = client.FirstName + " " + client.LastName }); } //MEMBERS //pull 'em into lists first var members = await _context.Members.ToListAsync(); /* * var uniquemembers = * from participant in members * join projectparticipant in projectroster * on participant.ID equals projectparticipant.ProjectParticipantID * where participant.ID != projectparticipant.ProjectParticipantID * select participant; */ List <SelectListItem> membersSelectList = new List <SelectListItem>(); var membersforedit = from participant in _context.Members join projectparticipant in _context.ProjectRoster on participant.ID equals projectparticipant.ProjectParticipantID where project.ID == projectparticipant.ProjectID select participant; int indx = -1; foreach (var member in members) { indx++; membersSelectList.Add(new SelectListItem { Value = member.ID, Text = member.FirstName + " " + member.LastName }); foreach (var item in membersforedit) { if (membersSelectList.Any(d => d.Value == item.ID)) { membersSelectList.RemoveAt(indx); indx--; } } } var clientsforedit = from participant in _context.Clients join projectparticipant in _context.ProjectRoster on participant.ID equals projectparticipant.ProjectParticipantID where project.ID == projectparticipant.ProjectID select participant; //foreach(var item in membersforedit){ // foreach(var item2 in membersSelectList){ // if(item2.Value == item.ID){ // membersSelectListToSend.Remove(item2); // } // } //} //create and prepare ViewModel EditProjectDetailViewModel epdvm = new EditProjectDetailViewModel { TheProject = project, ProjectClients = clientsforedit.ToList() ?? null, //ProjectMembers = membersforedit.ToList() ?? null, ProjectClientsList = clientsSelectList, ProjectMembersList = membersSelectList }; return(View(epdvm)); }
// GET: Projects/EditProjectParticipants/5 public async Task <IActionResult> EditProjectParticipants(string id) { if (id == null) { return(NotFound()); } var project = await _context.Projects.SingleOrDefaultAsync(m => m.ID == id); if (project == null) { return(NotFound()); } //var clients = await _context.Clients.ToListAsync(); //CLIENTS //pull 'em into lists first var clients = await _context.Clients.ToListAsync(); var projectroster = await _context.ProjectRoster.ToListAsync(); /* * var uniqueclients = * from participant in clients * join projectparticipant in projectroster * on participant.ID equals projectparticipant.ProjectParticipantID * where participant.ID != projectparticipant.ProjectParticipantID * select participant; */ List <SelectListItem> clientsSelectList = new List <SelectListItem>(); foreach (var client in clients) { clientsSelectList.Add(new SelectListItem { Value = client.ID, Text = client.FirstName + " " + client.LastName }); } //MEMBERS //pull 'em into lists first var members = await _context.Members.ToListAsync(); /* * var uniquemembers = * from participant in members * join projectparticipant in projectroster * on participant.ID equals projectparticipant.ProjectParticipantID * where participant.ID != projectparticipant.ProjectParticipantID * select participant; */ List <SelectListItem> membersSelectList = new List <SelectListItem>(); foreach (var member in members) { membersSelectList.Add(new SelectListItem { Value = member.ID, Text = member.FirstName + " " + member.LastName }); } //create and prepare ViewModel EditProjectDetailViewModel epdvm = new EditProjectDetailViewModel { TheProject = project, ProjectClientsList = clientsSelectList, ProjectMembersList = membersSelectList }; return(View(epdvm)); }
// GET: Projects/EditProjectParticipants/5 public async Task <IActionResult> EditProjectParticipants(string id) { if (id == null) { return(NotFound()); } var project = await _context.Projects.SingleOrDefaultAsync(m => m.ID == id); if (project == null) { return(NotFound()); } //var clients = await _context.Clients.ToListAsync(); //CLIENTS //pull 'em into lists first /* * var uniqueclients = * from participant in clients * join projectparticipant in projectroster * on participant.ID equals projectparticipant.ProjectParticipantID * where participant.ID != projectparticipant.ProjectParticipantID * select participant; */ var clients = await _context.Clients.ToListAsync(); var projectroster = await _context.ProjectRoster.ToListAsync(); var clientsOnProject = from participant in clients join projectparticipant in projectroster on participant.ID equals projectparticipant.ProjectParticipantID where participant.ID == projectparticipant.ProjectParticipantID select participant; var clientsNotOnProject = clients.Where(p => !clientsOnProject.Any(q2 => q2.ID == p.ID)); List <SelectListItem> clientsSelectList = new List <SelectListItem>(); foreach (var client in clientsNotOnProject) { clientsSelectList.Add(new SelectListItem { Value = client.ID, Text = client.FirstName + " " + client.LastName }); } //-------------------------------------------------------------------------------------------------------------------------------------------------------- var members = await _context.Members.ToListAsync(); var membersOnProject = from participant in members join projectparticipant in projectroster on participant.ID equals projectparticipant.ProjectParticipantID where participant.ID == projectparticipant.ProjectParticipantID select participant; var membersNotOnProject = members.Where(p => !membersOnProject.Any(p2 => p2.ID == p.ID)); //not contributing to a project foreach (var member in membersNotOnProject) { member.ToString(); Console.WriteLine(member); } /* * var uniquemembers = * from participant in members * join projectparticipant in projectroster * on participant.ID equals projectparticipant.ProjectParticipantID * where participant.ID != projectparticipant.ProjectParticipantID * select participant; */ List <SelectListItem> membersSelectList = new List <SelectListItem>(); foreach (var member in membersNotOnProject) { membersSelectList.Add(new SelectListItem { Value = member.ID, Text = member.FirstName + " " + member.LastName }); } //this is the key //mozna kdyz to udelam manualne tak to muzu udelat i tady //tri vars jenom copirujou uqiuemembers etc. EditProjectDetailViewModel epdvm = new EditProjectDetailViewModel { ProjectID = project.ID, TheProject = project, ProjectClientsList = clientsSelectList, ProjectMembersList = membersSelectList }; return(View(epdvm)); }
// GET: Projects/EditProjectParticipants/5 public async Task <IActionResult> EditProjectParticipants(string id) { if (id == null) { return(NotFound()); } //var project = await _context.Projects.SingleOrDefaultAsync(m => m.ID == id); //if (project == null) { // return NotFound(); //} ////var clients = await _context.Clients.ToListAsync(); ////CLIENTS ////pull 'em into lists first //var clients = await _context.Clients.ToListAsync(); //var projectroster = await _context.ProjectRoster.ToListAsync(); ///* //var uniqueclients = // from participant in clients // join projectparticipant in projectroster // on participant.ID equals projectparticipant.ProjectParticipantID // where participant.ID != projectparticipant.ProjectParticipantID // select participant; //*/ //List<SelectListItem> clientsSelectList = new List<SelectListItem>(); //foreach (var client in clients) { // clientsSelectList.Add(new SelectListItem { Value = client.ID, Text = client.FirstName + " " + client.LastName }); //} ////MEMBERS ////pull 'em into lists first //var members = await _context.Members.ToListAsync(); ///* //var uniquemembers = // from participant in members // join projectparticipant in projectroster // on participant.ID equals projectparticipant.ProjectParticipantID // where participant.ID != projectparticipant.ProjectParticipantID // select participant; //*/ //List<SelectListItem> membersSelectList = new List<SelectListItem>(); //foreach (var member in members) { // membersSelectList.Add(new SelectListItem { Value = member.ID, Text = member.FirstName + " " + member.LastName }); //} //create and prepare ViewModel //EditProjectDetailViewModel epdvm = new EditProjectDetailViewModel { // TheProject = project, // ProjectClientsList = clientsSelectList, // ProjectMembersList = membersSelectList //}; var client = await(from participant in _context.Clients join projectparticipant in _context.ProjectRoster on participant.ID equals projectparticipant.ProjectParticipantID where projectparticipant.ProjectID == id select participant).FirstOrDefaultAsync(); EditProjectDetailViewModel epdvm = await getPopulatedEditProjectDetailViewModel(id, client?.ID); if (epdvm.TheProject == null) { return(NotFound()); } return(View(epdvm)); }