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 void CreateNewPropertyTest1()
 {
     ProjectsReader target = new ProjectsReader(); // TODO: Initialize to an appropriate value
     string name = "Можно даже кирилическое название";
     string systemName = "latin_only";
     string type = "Percentage";
     target.CreateNewProperty(name, systemName, type, null);
 }
 public void CreateNewPropertyTest2()
 {
     ProjectsReader target = new ProjectsReader(); // TODO: Initialize to an appropriate value
     string type = "Percentage";
     string name = "Name";
     string systemName = "it should be single word";
     Object forException = null;
     try
     {
         target.CreateNewProperty(name, systemName, type, null);
     }
     catch (Exception e)
     {
         forException = e;
     }
     Assert.IsTrue(forException is BadSystemNameException);
 }
        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 CreateNewPropertyTest3()
 {
     ProjectsReader target = new ProjectsReader(); // TODO: Initialize to an appropriate value
     string name = "Можно даже кирилическое название";
     string type = "Percentage";
     string systemName = "hello,world";
     Object forException = null;
     try
     {
         target.CreateNewProperty(name, systemName, type, null);
     }
     catch (Exception e)
     {
         forException = e;
     }
     Assert.IsTrue(forException is BadSystemNameException);
 }
 public void GetPropertiesDefinitionsTest()
 {
     ProjectsReader target = new ProjectsReader(); // TODO: Initialize to an appropriate value
     int projectId = 0; // TODO: Initialize to an appropriate value
     IProperty[] actual;
     actual = target.GetPropertiesDefinitions(projectId);
     Assert.IsNotNull(actual);
     foreach (Property property in actual)
     {
         Assert.IsTrue(property.DisplayName.Length > 0);
         Assert.IsTrue(property.SystemName != null);
         Assert.IsTrue(Regex.IsMatch(property.SystemName, @"\A\w{1,}\z"));
         Assert.IsTrue(property.Type == "String" || property.Type == "Select" || property.Type == "Multyselect" || property.Type == "Number" || property.Type == "Percentage");
     }
 }
 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 AjaxValueOperation(int id, Object Value)
 {
     if(!HttpContext.Request.IsAjaxRequest())
     {
         return Badrequest();
     }
     try
     {
         ValueModel model;
         ProjectsReader dal = new ProjectsReader();
         IValue original = dal.GetValue(id);
         HttpContextWarker contexter = new HttpContextWarker(HttpContext);
         bool canModify = contexter.CanModify(original.GetProject());
         if (contexter.Method.Equals(HttpVerbs.Post))
         {
             original.SetValue(Value);
             original.Author = contexter.User.Name;
             original.Time = DateTime.Now;
             model = new ValueModel(original, canModify);
             if(!canModify)
             {
                 throw new NotEnoughRightsException(ResourcesHelper.GetText("OnNotEnoughForModifyingValue", contexter.GetCulture()));
             }
             if(!ProjectHelper.Save(model))
             {
                 throw new InvalidUserInputException();
             }
         }
         else
         {
             model = new ValueModel(original, canModify);
         }
         return PartialView("JustLookValue", model);
     }
     catch(ProjectWatcher.Errors.ProjectWatcherException e)
     {
         return Json(new {error = e.Message}, JsonRequestBehavior.AllowGet);
     }
 }
 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});
     }
 }