public async Task <IActionResult> Edit(int id, [Bind("Id,RiskId,Name,Description,QuantitativeValue")][FromBody] RiskProperty riskProperty) { if (id != riskProperty.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(riskProperty); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RiskPropertyExists(riskProperty.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(Json(riskProperty)); }
/// <summary> /// Gets ProeprtyValue of risk of id /// </summary> /// <param name="id"></param> /// <param name="type"></param> /// <returns></returns> private string GetPropertyValue(Guid id, RiskPropertyTypes type) { RiskProperty property = _context.RiskProperties.Where(r => r.RiskId.Equals(id) && r.PropertyId.Equals((int)type)).FirstOrDefault(); if (property != null) { return(property.PropertyValue); } return("0"); }
/// <summary> /// Create new Risk /// </summary> /// <param name="risk"></param> public void Create(Risk risk) { _context.Risks.Add(risk); List <RiskProperty> riskProperties = new List <RiskProperty>(); foreach (RiskPropertyTypes type in (RiskPropertyTypes[])Enum.GetValues(typeof(RiskPropertyTypes))) { RiskProperty prop = new RiskProperty() { PropertyId = (int)type, PropertyValue = "1", RiskId = risk.Id }; riskProperties.Add(prop); } _context.RiskProperties.AddRange(riskProperties); _context.SaveChanges(); }
public async Task <IActionResult> Create([Bind("Id,RiskId,Name,Description,QuantitativeValue")][FromBody] RiskProperty riskProperty) { if (ModelState.IsValid) { while (true) { var existingProject = _context.RiskProperty.FirstOrDefault(r => r.Id == riskProperty.Id); if (existingProject != null) { riskProperty.Id = existingProject.Id + 1; } else { break; } } _context.Add(riskProperty); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(Json(riskProperty)); }