コード例 #1
0
 public static PropertyModel[] ExcludeProperties(ProjectsReader dal, PropertyModel[] propertiesFromProject)
 {
     IProperty[] propertiesFromDAL = dal.GetPropertiesDefinitions();
     PropertyModel[] modeledProperties = new PropertyModel[propertiesFromDAL.Length];
     for (int i = 0; i < propertiesFromDAL.Length; i++)
     {
         modeledProperties[i] = new PropertyModel(propertiesFromDAL[i]);
     }
     return modeledProperties.Except(propertiesFromProject).ToArray();
 }
コード例 #2
0
 /// <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});
 }
コード例 #3
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;
 }
コード例 #4
0
 public ActionResult NewProject()
 {
     ProjectsReader dal = new ProjectsReader();
     int newProjectId = dal.CreateNewProject(User.Identity.Name);
     return RedirectToAction("Index", "Project", new { projectId = newProjectId });
 }
コード例 #5
0
 internal static PropertyModel[] GetVisibleProperties(ProjectsReader dal, int projectId)
 {
     IProject project = dal.GetProject(projectId);
     if(project == null)
     {
         return null;
     }
     List<PropertyModel> outputProperties = new List<PropertyModel>();
     foreach (IValue value in project.GetValues())
     {
         if (!value.Visible)
         {
             continue;
         }
         PropertyModel property = new PropertyModel(value.GetProperty());
         property.IsImportant = value.Important;
         property.ProjectId = projectId;
         outputProperties.Add(property);
     }
     return outputProperties.ToArray();
 }