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});
 }
 /// <summary>
 /// Collects all necessary data for Footer.ascx
 /// </summary>
 /// <param name="culture">User language</param>
 /// <returns>Model for Footer.ascx</returns>
 public static FooterModel CreateFooterModel(String filter, String tableDefinition, HttpContextWarker context)
 {
     String culture = context.GetCulture();
     FooterModel model = new FooterModel();
     model.Filter = filter;
     model.TableDefinition = tableDefinition;
     model.AddProjectTitle = ResourcesHelper.GetText("AddProject", culture);
     model.IsAdmin = context.User.IsInRole("administrator");
     model.ExportTitle = ResourcesHelper.GetText("Export", culture);
     model.SubmitUploadTitle = ResourcesHelper.GetText("Upload", culture);
     model.UploadTitle = ResourcesHelper.GetText("Import", culture);
     return 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 });
        }
Ejemplo n.º 5
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 Index(string filter, string tableDefinition)
 {
     HttpContextWarker cultureProvider = new HttpContextWarker(HttpContext);
     if (filter == null)
     {
         filter = "";
     }
     if (tableDefinition == null)
     {
         tableDefinition = SettingsHelper.Instance.DefaultTableDefinition;
     }
     if (TempData["errorUpload"] != null)
     {
         ViewData["errorMessage"] = TempData["errorUpload"];
     }
     HttpContextWarker context = new HttpContextWarker(HttpContext);
     ViewData["filterModel"] = ProjectsHelper.CreateFilterModel(filter, tableDefinition, context.GetCulture());
     ViewData["tableModel"] = ProjectsHelper.CreateTableModel(filter, tableDefinition, HttpContext);
     ViewData["footerModel"] = ProjectsHelper.CreateFooterModel(filter, tableDefinition, context);
     TempData["exportData"] = ProjectsHelper.CreateExportData((TableModel)ViewData["tableModel"]);
     return View();
 }
 /// <summary>
 /// For using in "ProjectsHelper.ParseForColumns"
 /// </summary>
 /// <param name="comaSeparatedProperties">One line of definition</param>
 /// <returns>Model for column with "user-format exception in header"</returns>
 /// <exception cref="ArguementException"/>
 private static ColumnDefinition StringToColumn(string comaSeparatedProperties, HttpContextBase context)
 {
     if (context == null)
     {
         throw new ArgumentException();
     }
     ColumnDefinition toReturn = new ColumnDefinition();
     string[] properties = Regex.Split(comaSeparatedProperties, @"(?<!\\),");
     if (properties.Length != 4)
     {
         HttpContextWarker cultureProvider = new HttpContextWarker(context);
         String culture = cultureProvider.GetCulture();
         String message = ResourcesHelper.GetText("BadColumnDefinition", culture);
         throw new ArgumentException(message);
     }
     for (int i = 0; i < 4; i++)
     {
         properties[i] = Regex.Match(properties[i], @"\A *(.*?) *\z").Groups[1].Value;
     }
     toReturn.Header = properties[0];
     toReturn.Formula = properties[1];
     toReturn.Type = properties[2];
     try
     {
         toReturn.Width = Int32.Parse(properties[3]);
     }
     catch
     {
         HttpContextWarker cultureProvider = new HttpContextWarker(context);
         String culture = cultureProvider.GetCulture();
         String message = ResourcesHelper.GetText("BadWidthDefinition", culture);
         throw new ArgumentException(message);
     }
     return toReturn;
 }
 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 CreationOfNewProperty(int projectId)
 {
     ViewData["projectId"] = projectId;
     HttpContextWarker cultureProvider = new HttpContextWarker(HttpContext);
     string culture = cultureProvider.GetCulture();
     ViewData["projectId"] = projectId;
     ViewData["nameTitle"] = ResourcesHelper.GetText("Name", culture);
     ViewData["sysNameTitle"] = ResourcesHelper.GetText("SystemName", culture);
     ViewData["typeTitle"] = ResourcesHelper.GetText("Type", culture);
     ViewData["availableValuesTitle"] = ResourcesHelper.GetText("ValuesInEnumeration", culture);
     ViewData["isImportantTitle"] = ResourcesHelper.GetText("IsImportant", culture);
     PropertyModel model = new PropertyModel();
     model.Name = "";
     model.SystemName = "";
     model.Type = "String";
     model.AvailableValues = "";
     ViewData["availableTypes"] = ProjectHelper.GetAvailableTypesForDropdown();
     return PartialView("CreateProperty", model);
 }