/// <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> /// Sends value to DAL. /// </summary> /// <param name="model">What to save.</param> /// <returns>If operation commited succesfully.</returns> internal static bool Save(ValueModel model) { Modifier modifier = new Modifier(); return modifier.Modify(model.DalValue); }