예제 #1
0
 // Register
 public HttpResponseMessage RegisterGoogle(RegisterUserGoogleRequest model)
 {
     if (!ModelState.IsValid)
     {
         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
     }
     //If email already exists, store their google 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.AddGoogleId(userId, model.GoogleId);
             return Request.CreateResponse(HttpStatusCode.OK, resp);
         }
         catch (Exception ex)
         {
             return Request.CreateResponse(HttpStatusCode.OK, ex);
         }
     }
     //If no email, create new account, and add google id to google table.
     try
     {
         ItemResponse<int> resp = new ItemResponse<int>();
         resp.Item = _userService.RegisterGoogle(model);
         return Request.CreateResponse(HttpStatusCode.OK, resp);
     }
     catch (Exception ex)
     {
         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
     }
 }
예제 #2
0
        //Register User through Google Login - sets role to User
        public int RegisterGoogle(RegisterUserGoogleRequest model)
        {
            int Id = 0;

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

                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);
        }