public IActionResult Edit(LifterModel lifter, string id) { var lifterToCreate = _updateHelper.CopyNonNullItems(lifter, _repository.GetItemAsync(id).Result); var lifterToReturn = _repository.UpdateItemAsync(id, lifterToCreate).Result; return(RedirectToAction(nameof(Details), new { id = lifterToReturn.Id })); }
public void TestController() { var repo = new DocumentDBRepository <LifterModel>(); var helper = new UpdateModel <LifterModel>(); var controller = new LifterController(repo, helper); LifterModel testLifter = new LifterModel { Age = "19", Name = "Dylan", Weight = "185", LiftingNumbers = new LiftingNumbersModel { Squat = "385", Bench = "275", Deadlift = "485" } }; controller.CreateLifter(testLifter); var model = repo.CreateItemAsync(testLifter).Result; JsonResult result = (JsonResult)controller.GetLifter(model.Id); testLifter.Id = model.Id; JsonResult expected = new JsonResult(testLifter); Assert.AreEqual(result.ToString(), expected.ToString()); }
public IActionResult CreateLifter([FromBody] LifterModel lifter) { if (lifter == null) { return(BadRequest()); } var lifterToReturn = _repository.CreateItemAsync(lifter).Result; return(CreatedAtRoute("GetLifter", new { id = lifterToReturn.Id }, lifterToReturn)); }
public IActionResult UpdateLifter([FromBody] LifterModel lifter, string id) { if (lifter == null) { return(BadRequest()); } var lifterToCreate = _updateHelper.CopyNonNullItems(lifter, _repository.GetItemAsync(id).Result); if (lifterToCreate == null) { return(BadRequest()); } var returnItem = _repository.UpdateItemAsync(id, lifterToCreate).Result; return(CreatedAtRoute("GetLifter", new { id = lifterToCreate.Id }, lifterToCreate)); }
public IActionResult Create(LifterModel lifter) { LifterModel lifterToAdd = new LifterModel { Type = "lifter", Name = lifter.Name, Gender = lifter.Gender, Age = lifter.Age, Weight = lifter.Weight, LiftingNumbers = new LiftingNumbersModel { Squat = lifter.LiftingNumbers.Squat, Bench = lifter.LiftingNumbers.Bench, Deadlift = lifter.LiftingNumbers.Deadlift } }; var lifterToReturn = _repository.CreateItemAsync(lifterToAdd).Result; return(RedirectToAction(nameof(Details), new { id = lifterToReturn.Id })); }
public WilksCalculator(LifterModel lifter) { _lifter = lifter; }