public IActionResult RegisterNinja(NinjaView model) { if (ModelState.IsValid) { Ninja ninja = new Ninja { name = model.name, level = model.level, dojo_id = model.dojo_id }; ninjaFactory.AddNewNinja(ninja); return(RedirectToAction("Index")); } return(View(model)); }
public HttpResponseMessage AddNinja([FromBody] NinjaView ninja) { try { if (ninja == null) { throw new ArgumentNullException("Model not valid"); } unitOfWork.Ninjas.Add(Mapper.Map <Ninja.Domain.Ninja>(ninja)); var response = unitOfWork.Complete(); return(Request.CreateResponse(HttpStatusCode.OK, response)); } catch (ArgumentNullException eNull) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, eNull.Message)); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message)); } }
// Pass view into model. public void SetView(NinjaView theView) { myView = theView; }