public ActionResult AddProperties(int projectId)
 {
     HttpContextWarker contexter = new HttpContextWarker(HttpContext);
     ProjectsReader dal = new ProjectsReader();
     IProject projectToShow = dal.GetProject(projectId);
     if(!contexter.CanModify(projectToShow))
     {
         return RedirectToAction("NotEnoughRights");
     }
     string culture = contexter.GetCulture();
     ViewData["projectProperties"] = ResourcesHelper.GetText("ProjectProperties", culture);
     ViewData["availableProperties"] = ResourcesHelper.GetText("AvailableProperties", culture);
     ViewData["createPropertyTitle"] = ResourcesHelper.GetText("CreateProperty", culture);
     ViewData["backToProjectViewTitle"] = ResourcesHelper.GetText("BackToProjectView", culture);
     ViewData["nameTitle"] = ResourcesHelper.GetText("Name", culture);
     ViewData["systemNameTitle"] = ResourcesHelper.GetText("SystemName", culture);
     ViewData["typeTitle"] = ResourcesHelper.GetText("Type", culture);
     ViewData["isImportantTitle"] = ResourcesHelper.GetText("IsImportant", culture);
     ViewData["removeTitle"] = ResourcesHelper.GetText("Remove", culture);
     ViewData["addTitle"] = ResourcesHelper.GetText("Add", culture);
     ProjectModel model = new ProjectModel();
     model.Id = projectId;
     model.ProjectProperties = ProjectHelper.GetVisibleProperties(dal, model.Id);
     if (model.ProjectProperties == null)
     {
         return RedirectToAction("BadRequest");
     }
     PropertyModel[] existingProperties = ProjectHelper.ExcludeProperties(dal, model.ProjectProperties);
     model.OtherProperties = existingProperties;
     return View(model);
 }
        public ActionResult AddExistingProperty(int projectId, string systemName)
        {
            HttpContextWarker contexter = new HttpContextWarker(HttpContext);
            ProjectsReader dal = new ProjectsReader();
            IProject actualProject = dal.GetProject(projectId);
            if (contexter.CanModify(actualProject))
            {
                try
                {
                    actualProject.AddProperty(systemName, true, true, User.Identity.Name);
                }
                catch (ConnectionException e)
                {
                    HttpContextWarker context = new HttpContextWarker(HttpContext);
                    TempData["errorMessage"] = ResourcesHelper.GetText("ConnectionError", context.GetCulture());
                }

            }
            return RedirectToAction("AddProperties", new { projectId = projectId });
        }
 public void GetProjectTest()
 {
     ProjectsReader target = new ProjectsReader();
     int projectId = 5;
     IProject actual;
     actual = target.GetProject(projectId);
     Assert.IsNotNull(actual);
     Assert.IsNotNull(actual.GetValue("owner"));
 }
 public ActionResult Index(int projectId)
 {
     HttpContextWarker cultureProvider = new HttpContextWarker(HttpContext);
     string culture = cultureProvider.GetCulture();
     ProjectsReader dal = new ProjectsReader();
     IProject project = dal.GetProject(projectId);
     if(project == null)
     {
         return RedirectToAction("BadRequest");
     }
     ProjectWithValuesModel model = new ProjectWithValuesModel(project);
     model.IsEditable = (HttpContext.User.IsInRole("administrator") ||
                         model.Owner == HttpContext.User.Identity.Name)
                            ? true
                            : false;
     return View(model);
 }
 public PartialViewResult EditValue(Int32 id)
 {
     ProjectsReader reader = new ProjectsReader();
     IValue value = reader.GetValue(id);
     IProject project = reader.GetProject(value.ProjectId);
     HttpContextWarker contexter = new HttpContextWarker(HttpContext);
     if(!contexter.CanModify(project))
     {
         throw new NotEnoughRightsException();
     }
     ValueModel model = new ValueModel(reader.GetValue(id), true);
     ViewData["culture"] = contexter.GetCulture();
     return PartialView("ValueEdit", model);
 }
 public ActionResult DeleteProperty(int projectId, string systemName)
 {
     HttpContextWarker contexter = new HttpContextWarker(HttpContext);
     ProjectsReader dal = new ProjectsReader();
     IProject actualProject = dal.GetProject(projectId);
     if (contexter.CanModify(actualProject))
     {
         actualProject.DeleteProperty(systemName);
     }
     return RedirectToAction("AddProperties", new { projectId = projectId });
 }
 public PartialViewResult ChangeImportance(String systemName, int projectId)
 {
     HttpContextWarker contexter = new HttpContextWarker(HttpContext);
     ProjectsReader dal = new ProjectsReader();
     IProject project = dal.GetProject(projectId);
     if(!contexter.CanModify(project))
     {
         throw new NotEnoughRightsException();
     }
     IValue toChange = project.GetValues().FirstOrDefault(x => x.SystemName == systemName);
     if (toChange == null)
     {
         return PartialView("ChangeImportance",
             new PropertyModel { IsImportant = false, ProjectId = projectId, SystemName = systemName });
     }
     else
     {
         Modifier modifier = new Modifier();
         toChange.Important = !toChange.Important;
         modifier.ModifyImportance(toChange);
         return PartialView("ChangeImportance", new PropertyModel { IsImportant = toChange.Important, ProjectId = toChange.ProjectId, SystemName = toChange.SystemName});
     }
 }