Exemplo n.º 1
0
 // Register
 public HttpResponseMessage RegisterFacebook(RegisterUserFacebookRequest model)
 {
     if (!ModelState.IsValid)
     {
         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
     }
     //If email already exists, store their facebook id > if already stored, return message and continue
     int userId = _userService.GetByEmail(model.Email);
     if (userId > 0)
     {
         try
         {
             ItemResponse<int> resp = new ItemResponse<int>();
             resp.Item = _userService.AddFacebookId(userId, model.FbId, model.Picture);
             return Request.CreateResponse(HttpStatusCode.OK, resp);
         }
         catch (Exception ex)
         {
             return Request.CreateResponse(HttpStatusCode.OK, ex);
         }
     }
     //If no email, create new account, and add facebook id to facebook table.
     try
     {
         ItemResponse<int> resp = new ItemResponse<int>();
         resp.Item = _userService.RegisterFacebook(model);
         return Request.CreateResponse(HttpStatusCode.OK, resp);
     }
     catch (Exception ex)
     {
         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
     }
 }
Exemplo n.º 2
0
        //Register User through Facebook Login - sets role to User
        public int RegisterFacebook(RegisterUserFacebookRequest model)
        {
            int Id = 0;

            DataProvider.ExecuteNonQuery(storedProc : "dbo.UserBaseFacebook_Insert", inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Email", model.Email);
                paramCollection.AddWithValue("@EmailConfirmed", model.EmailConfirmed);
                paramCollection.AddWithValue("@Locked", model.Locked);
                paramCollection.AddWithValue("@FbId", model.FbId);
                paramCollection.AddWithValue("@FirstName", model.FirstName);
                paramCollection.AddWithValue("@LastName", model.LastName);
                paramCollection.AddWithValue("@Picture", model.Picture);

                SqlParameter idParameter = new SqlParameter("@Id", System.Data.SqlDbType.Int);
                idParameter.Direction    = System.Data.ParameterDirection.Output;

                paramCollection.Add(idParameter);
            }, returnParameters : delegate(SqlParameterCollection param)
            {
                Int32.TryParse(param["@Id"].Value.ToString(), out Id);
            });
            return(Id);
        }