public SessionDetails SignIn(CreateSessionDetails details) { // So normally, if you had a restful service listening, then you would do something like this : //return _webClient.PostWithResponse<CreateSessionDetails, SessionDetails>("sessions", details); // But for this example, we'll fake some validation, and response var errors = new List<Error>(); if (string.IsNullOrWhiteSpace(details.Email)) { errors.Add(new Error { Key = "Email", Value = "The 'Email' field is required" }); } if (string.IsNullOrWhiteSpace(details.Password)) { errors.Add(new Error { Key = "Password", Value = "The 'Password' field is required" }); } if (errors.Count > 0) { throw new Http400(errors); } return new SessionDetails { UserId = DateTime.Now.Ticks.ToString(), SessionKey = new Guid().ToString(), UserName = details.Email, }; }
public ActionResult SignIn(CreateSessionDetails details) { return _client.SignIn(details, session => Redirect("~") .WithSessionInitialised(_sessionProvider, session), errors => View(details).WithModelErrors(ModelState, errors) ); }
public ActionResult SignIn(CreateSessionDetails details, Func<SessionDetails, ActionResult> onSuccess, Func<IEnumerable<Error>, ActionResult> onError) { return Try(() => onSuccess.Invoke(_userServiceClient.SignIn(details)), onError); }