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);
 }
 /// <summary>
 /// Gives input csv-file to the DAL layer
 /// </summary>
 /// <param name="uploadFile">csv-file</param>
 /// <returns>if operation ended successfully</returns>
 public ActionResult Import(HttpPostedFileBase uploadFile, String filter, String tableDefinition)
 {
     HttpContextWarker contexter = new HttpContextWarker(HttpContext);
     String culture = contexter.GetCulture();
     if (uploadFile == null)
     {
         TempData["errorUpload"] = ResourcesHelper.GetText("ErrorWhileUploading", culture);
         return RedirectToAction("Index", new { filter = filter, tableDefinition = tableDefinition });
     }
     CsvParser parser = new CsvParser(uploadFile.InputStream);
     Dictionary<int, Evaluation> newRecords = parser.GetValuesForProjects();
     if(newRecords == null)
     {
         TempData["errorUpload"] = ResourcesHelper.GetText("BadInputCsvFileFormat", contexter.GetCulture());
         return RedirectToAction("Index", new { filter = filter, tableDefinition = tableDefinition });
     }
     List<int> badProjects = new List<int>();
     List<int> badRights = new List<int>();
     Modifier modifier = new Modifier();
     ProjectsReader reader = new ProjectsReader();
     foreach (KeyValuePair<int, Evaluation> project in newRecords)
     {
         IProject modifying = reader.GetProject(project.Key);
         if(!contexter.CanModify(modifying))
         {
             badRights.Add(project.Key);
             continue;
         }
         if (!modifier.ModifyOrCreate(project.Key, project.Value.Values, (RolablePrincipal)HttpContext.User))
         {
             badProjects.Add(project.Key);
         }
     }
     if (badProjects.Count > 0 || badRights.Count > 0)
     {
         TempData["errorUpload"] = ProjectsHelper.FormUploadErrorMessage(badProjects, badRights, culture);
     }
     else
     {
         TempData["errorUpload"] = ResourcesHelper.GetText("ImportSuccess", culture);
     }
     return RedirectToAction("Index", new { filter = filter, tableDefinition = tableDefinition});
 }
        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 });
        }
Ejemplo n.º 4
0
 internal static string CreateNewProperty(int projectId, PropertyModel model, bool important, HttpContextWarker contexter)
 {
     ProjectsReader dal = new ProjectsReader();
     IProject currentProject = dal.GetProject(projectId);
     String culture = contexter.GetCulture();
     if (!contexter.CanModify(currentProject))
     {
         return ResourcesHelper.GetText("NotEnoughRigts", culture);
     }
     try
     {
         dal.CreateNewProperty(model.Name, model.SystemName, model.Type, model.AvailableValuesAsArray);
     }
     catch (BadSystemNameException)
     {
         return ResourcesHelper.GetText("BadPropertySystemName", culture);
     }
     catch (BadPropertyTypeException)
     {
         return ResourcesHelper.GetText("BadPropertyType", culture);
     }
     catch (ConnectionException)
     {
         return ResourcesHelper.GetText("ConnectionError", culture);
     }
     catch (BadDisplayTypeNameException)
     {
         return ResourcesHelper.GetText("BadDisplayType", culture);
     }
     try
     {
         currentProject.AddProperty(model.SystemName, true, important, contexter.User.Identity.Name);
     }
     catch (ConnectionException e)
     {
         return ResourcesHelper.GetText("ConnectionError", contexter.GetCulture());
     }
     return null;
 }
 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 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});
     }
 }