예제 #1
0
        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));
        }
예제 #2
0
        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));
            }
        }
예제 #3
0
 // Pass view into model.
 public void SetView(NinjaView theView)
 {
     myView = theView;
 }