public async Task <IActionResult> Edit(MeasurementEditViewModel model) { if (!ModelState.IsValid) { if (model.Id == 0) { _pageContext.Title = "Edit " + model.Name; } else { _pageContext.Title = "Create measurement"; } return(View("Edit", model)); } try { Measurement measurement; if (model.Id == 0) { measurement = new Measurement(); _context.Measurements.Add(measurement); } else { measurement = _context.Find <Measurement>(model.Id); } Mapper.Map(model, measurement); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (model.Id > 0 && !MeasurementExists(model.Id)) { _pageContext.Title = "Edit " + model.Name; return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(MeasurementEditViewModel measurement) { return(await Edit(measurement)); }