Exemplo n.º 1
0
		public async Task<ActionResult> Index(int? pageIndex, int? pageSize, string projectId)
		{
			ProjectsRepository repository = new ProjectsRepository();
			ProjectListViewModel model = new ProjectListViewModel();

			if (pageIndex == null) { model.PageIndex = 0; }
			else { model.PageIndex = (int)pageIndex; }

			if (pageSize == null) { model.PageSize = 10; }
			else { model.PageSize = (int)pageSize; }

			try
			{
				SPListConfig cfg = new SPListConfig();
				await cfg.ConfigureSharePoint();

				var r = await repository.GetProjects(model.PageIndex, model.PageSize);
				model.Projects = r.ToList();
			}
			catch (RedirectRequiredException x)
			{
				return Redirect(x.RedirectUri.ToString());
			}
			return View(model);
		}
		public async Task<ActionResult> Create(Project project)
		{
			try
			{
				ProjectsRepository projectRepository = new ProjectsRepository();
				var result = await projectRepository.CreateProject(project);
				return RedirectToAction("Index", "Home");
			}
			catch (RedirectRequiredException x)
			{
				return Redirect(x.RedirectUri.ToString());
			}
		}
		public async Task<ActionResult> Delete(Project project)
		{
			try
			{
				ProjectsRepository repository = new ProjectsRepository();
				if (await repository.DeleteProject(project.Id, project.__eTag))
				{
					return RedirectToAction("Index", "Home");
				}
				else
				{
					return View(project);
				}
			}
			catch (RedirectRequiredException x)
			{
				return Redirect(x.RedirectUri.ToString());
			}
		}
		public async Task<ActionResult> Edit(Project project)
		{
			try
			{
				ProjectsRepository repository = new ProjectsRepository();
				if (await repository.UpdateProject(project))
				{
					return RedirectToAction("View", "Home", new { projectId = project.Id });
				}
				else
				{
					return View(project);
				}
			}
			catch (RedirectRequiredException x)
			{
				return Redirect(x.RedirectUri.ToString());
			}
		}
Exemplo n.º 5
0
		public async Task<ActionResult> View(string projectId)
		{
			ProjectDetailViewModel model = new ProjectDetailViewModel();
			ProjectsRepository projectRepository = new ProjectsRepository();
			ReferencesRepository referenceRepository = new ReferencesRepository();

			int id = -1;
			try
			{
				if (Int32.TryParse(projectId, out id))
				{
					model.Project = await projectRepository.GetProject(id, String.Empty);
					model.References = (await referenceRepository.GetReferencesForProject(id)).ToList();
				}
			}
			catch (RedirectRequiredException x)
			{
				return Redirect(x.RedirectUri.ToString());
			}
			return View(model);
		}
		private async Task<ActionResult> GetForEditDelete(int id)
		{
			ProjectsRepository projectRepository = new ProjectsRepository();

			Project project = null;
			try
			{
				project = await projectRepository.GetProject(id, String.Empty);
			}
			catch (RedirectRequiredException x)
			{
				return Redirect(x.RedirectUri.ToString());
			}
			return View(project);
		}
		private async Task<ProjectDetailViewModel> GetProjectAndReferencesFromSharePoint(string projectId)
		{
			ProjectDetailViewModel model = new ProjectDetailViewModel();
			ProjectsRepository projectRepository = new ProjectsRepository();
			ReferencesRepository referenceRepository = new ReferencesRepository();

			int id = -1;
			if (Int32.TryParse(projectId, out id))
			{
				model.Project = await projectRepository.GetProject(id, String.Empty);
				model.References = (await referenceRepository.GetReferencesForProject(id)).ToList();
			}
			return model;
		}