/// <summary> /// Delete an item from the project list /// </summary> /// <param name="Id"></param> public static void Delete(int Id) { Project toDelete = AllProjects.Find(proj => proj.Id == Id); if (toDelete != null) { AllProjects.Remove(toDelete); } Serialize(); }
public void ModifyEntity(Project project) { ProjectDTO projectDTO = AllProjects.Where <ProjectDTO>(x => x.ID == project.ID).FirstOrDefault(); if (projectDTO == null) { projectDTO = new ProjectDTO() { ID = project.ID, Name = project.Name, Contractor = project.Contractor == null ? null : new CompanyDTO { ID = project.Contractor.ID, Name = project.Contractor.Name }, Customer = new CompanyDTO { ID = project.Customer.ID, Name = project.Customer.Name }, Priority = project.Priority, EndProject = project.EndProject }; AllProjects.Add(projectDTO); } else { AllProjects.Remove(projectDTO); projectDTO = new ProjectDTO() { ID = project.ID, Name = project.Name, Contractor = project.Contractor == null ? null : new CompanyDTO { ID = project.Contractor.ID, Name = project.Contractor.Name }, Customer = new CompanyDTO { ID = project.Customer.ID, Name = project.Customer.Name }, EndProject = project.EndProject }; AllProjects.Add(projectDTO); } }
public static List <ValidationMessage> SaveProject( ValidatableParameter <string> projectId, ValidatableParameter <string> details, ValidatableParameter <bool> active ) { List <ValidationMessage> errors = new List <ValidationMessage>(); Guid projId = Guid.Empty; try { projId = new Guid(projectId.Value); } catch (FormatException) { errors.Add(new ValidationMessage { MessageText = "Project Id must be in the format dddddddd-dddd-dddd-dddd-dddddddddddd", Source = projectId.Source }); } if (string.IsNullOrEmpty(details.Value) || details.Value.Trim().Length == 0) { errors.Add(new ValidationMessage { MessageText = "Project Name must be supplied", Source = details.Source }); } else { //check for existing name with different id (name already in use) Project existItem = AllProjects.GetForName(details.Value); if (existItem != null && existItem.Id != projId) { errors.Add(new ValidationMessage { MessageText = string.Format("Project Name is already in use by project with Id {0}", existItem.Id.ToString()), Source = details.Source }); } } //perform update if no errors if (errors.Count == 0) { AllProjects items = new AllProjects(); Project newItem = new Project { Id = projId, Description = details.Value, Active = active.Value }; if (projId == Guid.Empty) { newItem.Id = Guid.NewGuid(); //set id items.Add(newItem); } else { Project existItem = items.Where(i => i.Id == projId).Single(); items.Remove(existItem); items.Add(newItem); } items.Save(); } return(errors); }
void RemoveProjectCommandExecute() { _projectRepository.Remove(testProject); AllProjects.Remove(testProject); }