// Save project partial private void SaveProjectPartial(ChangedValueObject changedValueObject, Project project) { if (changedValueObject.Name.Contains("WaterIn.")) { // Proceed WaterIn object if (project.WaterIn == null) { project.WaterIn = new Water(); } var waterIn = new WaterList(); waterIn.ImportWater(project.WaterIn); // Parse value like this: WaterIn.Na.Value string[] NameSplitted = changedValueObject.Name.Split("."[0]); if (NameSplitted.Length == 3 && NameSplitted[0] == "WaterIn") { ((WaterComponent)waterIn[NameSplitted[1]])[NameSplitted[2]] = Convert.ToDouble(changedValueObject.Value, CultureInfo.InvariantCulture); } waterIn.ExportWater(project.WaterIn); } else { //Proceed other values switch (changedValueObject.Name) { case "P.pHCorrection": project.pHCorrection = (ProjectBase.EnumpHCorrection)Convert.ToInt32(changedValueObject.Value); break; case "P.pHCorrected": project.pHCorrected = Convert.ToDouble(changedValueObject.Value, CultureInfo.InvariantCulture); break; case "P.RecoveryRO": project.RecoveryRO = Convert.ToDouble(changedValueObject.Value, CultureInfo.InvariantCulture); break; case "PasteROSA": // Parse ROSA HTML double recovery; var RosaResult = RosaParser.ParseRosa(changedValueObject.Value, project.WaterIn, out recovery); if (RosaResult) { project.RecoveryRO = recovery; } break; } } }
public async Task <IActionResult> PostPartial([FromBody] ChangedValueObject changedValueObject) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var project = await _context.Project.Include(p => p.WaterIn).SingleOrDefaultAsync(m => m.Id == changedValueObject.ProjectId); if (project == null) { return(NotFound()); } var currentUserId = _userManager.FindByNameAsync(User.Identity.Name).Result.Id; if (project.UserId != currentUserId) { return(Unauthorized()); } try { SaveProjectPartial(changedValueObject, project); _context.Update(project); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProjectExists(project.Id)) { return(NotFound()); } else { throw; } } return(this.CreatedAtAction("Get", new { }, true)); }