public ActionResult Register(RequestBinder req) { if (ModelState.IsValid) { try { if (_userRepository.Get(req.UserId) != null) { var response = _coffeeToken.CreateToken(req.UserId); // status =0 is no error return(Ok(JsonConvert.SerializeObject(response))); } User user = new User(); user.UserId = req.UserId; user.Fullname = req.Fullname; user.ProviderId = req.ProviderId; user.Image = req.Image; user.Status = 0; user.Role = 0; user.CreateDate = DateTime.Now; if (req.Identifier.Contains("@")) { user.Email = req.Identifier; } else { user.Phone = req.Identifier; } _userRepository.Add(user); if (_userRepository.SaveChanges() == 1) // register success { var response = _coffeeToken.CreateToken(req.UserId); return(Ok(JsonConvert.SerializeObject(response))); } } catch (Exception ex) { var response = new ResponseRegisterModel() { Token = null, Status = 1, RefreshToken = "", Error = "Error Server. " + ex.InnerException.Message }; // return(BadRequest(JsonConvert.SerializeObject(response))); } } return(BadRequest(ModelState)); }
protected override void Given() { var container = new Container(); subject = new RequestBinder(container, Substitute.For <IErrorMessageResolver>(), new ViolationPropertyNameResolver()); this.handler = new TestHandler(); this.methodInfo = this.handler.GetType().GetMethod("Get"); this.request = new TestRequest(); this.request.SetRequestBody("{\"Text\":\"some text\",\"Number\":3}"); this.request.ContentType = "application/json; charset=utf-8"; this.request.HttpMethod = HttpMethod.Post; this.routeValues = new RouteValues { { "routeParam", "3A814A58-C5B2-408D-BDA8-B80DDC725735" } }; BinderCollection.Initialize(container); }