public async Task <IActionResult> Update(ProjectUpdateViewModel viewModel) { if (ModelState.IsValid) { bool userIsClient = await _repository.UserIsClientAsync(viewModel.ProjectId, User); if (!userIsClient) { //TempData["error"] = "Du har ikke tillatelse til å endre dette prosjektet."; return(RedirectToAction("Index", "Project")); } Project project = new Project { ProjectId = viewModel.ProjectId, ProjectTitle = viewModel.ProjectTitle, ProjectDescription = viewModel.ProjectDescription, Active = viewModel.Active, Open = viewModel.Open, Complete = viewModel.Complete, Deadline = viewModel.Deadline }; await _repository.UpdateAsync(project); return(RedirectToAction("Read", "Project", new { id = viewModel.ProjectId })); } // If we get here, something was wrong with the model return(View(viewModel)); }
public async Task <IActionResult> Update(int id, ProjectUpdateViewModel model) { if (!TryValidateModel(model)) { return(View(model)); } Project projectToUpdate = _context.Projecten.SingleOrDefault(p => p.Id == id); projectToUpdate.Titel = model.Titel; projectToUpdate.Beschrijving = model.Beschrijving; projectToUpdate.Status = _context.Status.SingleOrDefault(s => s.Id == model.Status); using (var memoryStream = new MemoryStream()) { await model.newImage.CopyToAsync(memoryStream); projectToUpdate.Image = memoryStream.ToArray(); } List <string> newTags = new List <string>(); foreach (var tag in model.Tags.Split(' ')) { newTags.Add(tag.Trim()); } _context.AssignTags(newTags, projectToUpdate.Id); _context.Update(id, projectToUpdate); return(RedirectToAction("Project", new { id = projectToUpdate.Id })); }
public async Task <IActionResult> Update(ProjectUpdateViewModel model) { model.UserId = this.UserId; var result = await _projectRepository.UpdateAsync <ProjectUpdateViewModel>(model); TempData.AddResult(result); return(RedirectToAction("Index")); }
public ActionResult Create(int?projectId) { if (projectId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var viewModel = new ProjectUpdateViewModel() { ProjectId = projectId.Value }; return(View(viewModel)); }
public IActionResult Update(int id) { Project projectFromDb = _context.GetProject(id); ProjectUpdateViewModel vm = new ProjectUpdateViewModel { Titel = projectFromDb.Titel, Beschrijving = projectFromDb.Beschrijving, Status = projectFromDb.Status.Id, Image = projectFromDb.Image, Tags = string.Join(" ", projectFromDb.TagProjects.Select(t => t.Tag).Select(t => t.Naam).ToList()) }; return(View(vm)); }
public async Task <ActionResult> Update(ProjectUpdateViewModel viewModel) { if (ModelState.IsValid) { var project = await db.UpdateMapData(viewModel, AssignToNone.IsNone); db.UpdateProject(project); await db.SaveChangesAsync(); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } ViewBag.ProjectManagers = await db.IncludeProjectManagersDropdown(); return(new HttpStatusCodeResult(HttpStatusCode.NotModified)); }
public async Task <Project> UpdateMapData(ProjectUpdateViewModel updateViewModel, bool isNone) { var project = await db.Projects.Where(x => x.Id == updateViewModel.Id) .Include(x => x.ProjectManager).SingleOrDefaultAsync(); var projectManager = await db.Users.Where(x => x.Id == updateViewModel.ProjectManagerId).FirstOrDefaultAsync(); if (isNone == true && projectManager != null) { var assignments = await db.Assignments.Where(x => x.ProjectId == project.Id && x.AssingToNone == true && x.Project.ProjectManager == null).ToListAsync(); foreach (var assignment in assignments) { assignment.AssingToNone = false; db.Entry(assignment).Property(x => x.AssingToNone).IsModified = true; } await db.SaveChangesAsync(); } else if (isNone == false && projectManager == null) { var assigmentsDevs = await db.Users.SelectMany(x => x.Assignments).Where(x => x.ProjectId == project.Id).ToListAsync(); var noneAssigmentsForDev = await db.Assignments.Where(x => x.ProjectId == project.Id && x.ProjectId != null && x.AssingToNone == true).ToListAsync(); if (assigmentsDevs.Count > 0 && noneAssigmentsForDev.Count > 0) { db.Assignments.RemoveRange(assigmentsDevs); db.Assignments.RemoveRange(noneAssigmentsForDev); await db.SaveChangesAsync(); } else if (assigmentsDevs.Count > 0 && noneAssigmentsForDev.Count == 0) { db.Assignments.RemoveRange(assigmentsDevs); await db.SaveChangesAsync(); } else if (noneAssigmentsForDev.Count > 0 && assigmentsDevs.Count == 0) { db.Assignments.RemoveRange(noneAssigmentsForDev); await db.SaveChangesAsync(); } } project.Name = updateViewModel.Name; project.ProjectManager = projectManager; project.Code = updateViewModel.Code; return(project); }
public async Task <ActionResult> Create(ProjectUpdateViewModel viewModel) { if (ModelState.IsValid) { var update = new ProjectUpdate() { ProjectId = viewModel.ProjectId, Text = viewModel.Text, DateInserted = DateTime.Now }; db.ProjectUpdates.Add(update); await db.SaveChangesAsync(); return(RedirectToAction("Details", "Project", new { id = viewModel.ProjectId })); } return(View(viewModel)); }
public async Task <ActionResult> Update(int id) { if (id > 0) { var project = await db.GetProjectAndProjectManagertByIdAsync(id); if (project == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } AssignToNone.IsNone = project.ProjectManagerId == null ? true : false; ProjectUpdateViewModel viewModel = new ProjectUpdateViewModel(project.Code, project.Name, project.ProjectManagerId, id); ViewBag.ProjectManagers = await db.IncludeProjectManagersDropdown(project.ProjectManager); return(View(viewModel)); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
public async Task <ProjectUpdateViewModel> GetProjectUpdateVMAsync(int id) { Project project = await GetByIdAsync(id); // TODO: Hent ut freelancer som er knyttet til prosjektet // Hent ut en liste over alle tilgjengelige freelancere ProjectUpdateViewModel viewModel = new ProjectUpdateViewModel { ProjectId = project.ProjectId, ClientId = project.ClientId, ProjectTitle = project.ProjectTitle, ProjectDescription = project.ProjectDescription, Active = project.Active, Open = project.Open, Complete = project.Complete, Deadline = project.Deadline }; // TODO FULLFØR DENNE!!! return(viewModel); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound("Bad parameter")); } bool userIsClient = await _repository.UserIsClientAsync((int)id, User); if (!userIsClient) { //TempData["error"] = "Du har ikke tillatelse til å endre dette prosjektet."; return(RedirectToAction("Read", "Project", new { id = id })); } ProjectUpdateViewModel viewModel = await _repository.GetProjectUpdateVMAsync((int)id); if (viewModel == null) { return(NotFound("Project was not found")); } return(View(viewModel)); }
public IActionResult Put(int id, ProjectUpdateViewModel model) { var repo = this.Storage.GetRepository <IProjectRepository>(); Project project = repo.WithKey(id); if (project == null) { return(this.NotFound(new { success = false })); } if (this.ModelState.IsValid) { model.ToEntity(project, this.GetCurrentUserName()); repo.Edit(project, GetCurrentUserName()); this.Storage.Save(); return(Ok(new { success = true })); } return(BadRequest(new { success = false })); }
public async Task <IActionResult> ChangeFailureRateUpdates() { ServiceApiClient serviceApiClient = new ServiceApiClient(Configuration); //Get a list of settings List <AzureDevOpsSettings> azureDevOpsSettings = await serviceApiClient.GetAzureDevOpsSettings(); List <GitHubSettings> githubSettings = await serviceApiClient.GetGitHubSettings(); //Create project items from each Azure DevOps setting and add it to a project list. List <ProjectUpdateItem> projectList = new List <ProjectUpdateItem>(); foreach (AzureDevOpsSettings item in azureDevOpsSettings) { ProjectUpdateItem newItem = new ProjectUpdateItem { ProjectId = item.RowKey, ProjectName = item.Project }; projectList.Add(newItem); } //Create project items from each GitHub setting and add it to a project list. foreach (GitHubSettings item in githubSettings) { ProjectUpdateItem newItem = new ProjectUpdateItem { ProjectId = item.RowKey, ProjectName = item.Repo }; projectList.Add(newItem); } //Create a percentage completed dropdown List <CompletionPercentItem> completionList = new List <CompletionPercentItem> { new CompletionPercentItem { CompletionPercent = 0 }, new CompletionPercentItem { CompletionPercent = 10 }, new CompletionPercentItem { CompletionPercent = 25 }, new CompletionPercentItem { CompletionPercent = 50 }, new CompletionPercentItem { CompletionPercent = 75 }, new CompletionPercentItem { CompletionPercent = 98 }, new CompletionPercentItem { CompletionPercent = 100 } }; //Create the days to process dropdown List <NumberOfDaysItem> numberOfDaysList = new List <NumberOfDaysItem> { new NumberOfDaysItem { NumberOfDays = 1 }, new NumberOfDaysItem { NumberOfDays = 7 }, new NumberOfDaysItem { NumberOfDays = 21 }, new NumberOfDaysItem { NumberOfDays = 30 }, new NumberOfDaysItem { NumberOfDays = 60 }, new NumberOfDaysItem { NumberOfDays = 90 } }; ProjectUpdateViewModel model = new ProjectUpdateViewModel { ProjectList = new SelectList(projectList, "ProjectId", "ProjectName"), CompletionPercentList = new SelectList(completionList, "CompletionPercent", "CompletionPercent"), NumberOfDaysList = new SelectList(numberOfDaysList, "NumberOfDays", "NumberOfDays") }; return(View(model)); }
public void Setup() { _repository = new Mock <IProjectRepository>(); _fakeOpenAndActiveProjects = new List <Project> { new Project { ProjectTitle = "Tittel1", ProjectDescription = "Beskrivelse1", Active = true, Open = true, Complete = false }, new Project { ProjectTitle = "Tittel3", ProjectDescription = "Beskrivelse3", Active = true, Open = true, Complete = false } }; _fakeCompleteProjects = new List <Project> { new Project { ProjectTitle = "Tittel2", ProjectDescription = "Beskrivelse2", Active = false, Open = false, Complete = false }, new Project { ProjectTitle = "Tittel123", ProjectDescription = "Beskrivelse222222", Active = false, Open = false, Complete = false } }; _fakeActiveProjects = new List <Project> { _fakeOpenAndActiveProjects[0], _fakeOpenAndActiveProjects[1], new Project { ProjectTitle = "Tittel124563", ProjectDescription = "Beskrivelse2222221111", Active = true, Open = false, Complete = false }, new Project { ProjectTitle = "Tittel123456123", ProjectDescription = "Beskrivelse222222232323", Active = true, Open = false, Complete = false } }; _fakeProjects = new List <Project> { _fakeOpenAndActiveProjects[0], _fakeOpenAndActiveProjects[1], _fakeCompleteProjects[0], _fakeCompleteProjects[1], _fakeActiveProjects[2], _fakeActiveProjects[3] }; _fakeProjectList = new List <ProjectListViewModel> { // TODO: Utvides new ProjectListViewModel { ProjectTitle = "Tittel1", Active = true, Open = true, Complete = false }, new ProjectListViewModel { ProjectTitle = "Tittel3", Active = true, Open = true, Complete = false } }; _fakeProjectCreateVM = new ProjectCreateViewModel() { ProjectTitle = "Title", ProjectDescription = "Description", Active = true, Open = true, Deadline = DateTime.Now }; var fakeFreelancers = new List <FreelancerInfo> { new FreelancerInfo { FirstName = "Ola" }, new FreelancerInfo { FirstName = "Normann" } }; _fakeProjectUpdateVM = new ProjectUpdateViewModel { ProjectId = 1, ProjectTitle = "Title", ProjectDescription = "Description", Active = true, Open = true, Complete = false, Deadline = DateTime.Now, //Freelancers = fakeFreelancers }; _fakeProjectReadVM = new ProjectReadViewModel() { ProjectTitle = "Title", ProjectDescription = "Description", Active = true, Open = true, Complete = false, Deadline = DateTime.Now, DateCreated = DateTime.Now, Freelancer = fakeFreelancers[0], Client = new KlientInfo { CompanyName = "UiT Norges Arktiske Universitet" } }; }