2017-01-13 4 views
0

Webサービスでレコードを更新してから、Webサービスの別のメソッドから特定の人に電子メールを送信するWebアプリケーションを作成していますwebserviceでtry catchブロックを使用して、anglejsコントローラで結果を送信

のために私はメール

を送信するための更新

2の2つの方法

1を持っています210

SendEmailsms();

この行は私がこの

// automail store procedure email send dynamically 
    SqlCommand cmd = new SqlCommand("sonvinmailsmssend", con); 
    cmd.CommandType = CommandType.StoredProcedure; 
    cmd.Parameters.AddWithValue("@brandname", brandname.ToString()); 
    cmd.Parameters.AddWithValue("@zone", zone.ToString()); 
    cmd.Parameters.AddWithValue("@location", location.ToString()); 
    cmd.Parameters.AddWithValue("@property", property.ToString()); 
    SqlDataAdapter da = new SqlDataAdapter(cmd); 

のように見えますが、時には複数のレコードが同じ名前で保存があるストアドプロシージャを呼び出しています、私の第二の方法では

第二の方法を呼んでいます私のデータベースので、私はエラーが表示されます

サブクエリが返します1より大きい値

は、私はちょうど私が私のコントローラで何をする必要があるか

try 
{ 

     // automail store procedure email send dynamically 
     SqlCommand cmd = new SqlCommand("sonvinmailsmssend", con); 
     cmd.CommandType = CommandType.StoredProcedure; 
     cmd.Parameters.AddWithValue("@brandname", brandname.ToString()); 
     cmd.Parameters.AddWithValue("@zone", zone.ToString()); 
     cmd.Parameters.AddWithValue("@location", location.ToString()); 
     cmd.Parameters.AddWithValue("@property", property.ToString()); 
     SqlDataAdapter da = new SqlDataAdapter(cmd); 
} 

catch 
{ 
//what i need to write here?? 
} 

のように、ここで

をトライcatchブロックを使用したいです?

$http.get('/csuv5.asmx/updcomson', { 
      params: { 
       //params 
      } 
     }) 

     .then(function (response) { 

//ここで何をする必要がありますか? });

+0

名前をuniqeにして、非一意の名前のフィールドを追加しますか? –

+0

何を返そうとしていますか、例外をキャッチしたら何をしたいですか? – abhi

答えて

1

サービス: あなたはリストにupdcomsonや辞書の戻り値の型を変更する必要が

public List<string> updcomson(string Id, string upddate, string updcomname, string updbrandname, string updzone, string updlocation, string updstartime, string updendtime, string updprogram, string updvenue, string updvenuename, string pm, string pax) 
    { 
    //updating 
    string errMessage = SendEmailsms(); 
    con.Close(); 
    var json = js.Serialize(message); 
    Context.Response.Write("{" + '"' + "message" + '"' + ":" + json + "}"); 

     List<string> plist = new List<string>(); 
     plist.Add(errMessage); 
     return plist; 
    } 

SendEmailSMS()、無効

catch(Exception ex){ 
// return the message you want to 
return ex.Message; 
} 

から文字列に変更し、戻り値の型の//例外ブロック角:このようなもの

$http.get('/csuv5.asmx/updcomson', { 
      params: { 
       //params 
      } 
     }) 

     .then(function (response) { 
$scope.returnMessage= response.data;  
//now you have your returned value in $scope.returnMessage, use it in alert or to show in a label as error 
}); 

////////あなたのコントローラからIHttpActionResultを返すことができ

var LoginApp = angular.module('LoginApp',[]); 

LoginApp.controller('LoginController', function ($scope, $http, $window) { 
    $scope.LoginAuth = function() 
    { 
     var dataToPost = { 
      'UserID': $("#txtUserid").val(), 
      'Password': $("#txtPassword").val() 
     } 

     var url = 'http://localhost:52212/api/Login/Authenticate'; 

     $http.post(url, dataToPost).then(function (response) { 
      $scope.isAuth = response.data; 
      if ($scope.isAuth) { 
       //$window.location.href = 'Index.html'; 
       $window.location.href = 'customscripts/js/Index.html'; 
      } 
      else 
      { 
       alert("Wrong Username/Password"); 
       //$window.location.href = 'Login.html'; 
       $window.location.href = 'customscripts/js/Login.html'; 
      } 
     }); 
    } 
}); 
0

:私のコード /////

public class LoginController : ApiController 
    { 
     [HttpPost] 
     [Route("api/Login/Authenticate")] 
     public bool isAuthenticate(LoginVal val) 
     { 
      bool auth = false; 
      using (HostingEnvironment.Impersonate()) 
      { 
       PrincipalContext ctx = new PrincipalContext(ContextType.Domain); 
       if (ctx.ValidateCredentials (val.UserID, val.Password)) 
       { 
        auth = true; 
       } 
      } 
      return auth; 
     } 
    } 

角度から 小さな例

//C# controller 
//You also need to inherit your controller from ApiConroller 
// public class MyController : ApiConroller {//the code...} 


    public void updcomson(string Id, string upddate, string updcomname, string updbrandname, string updzone, string updlocation, string updstartime, string updendtime, string updprogram, string updvenue, string updvenuename, string pm, string pax) 
{ 
    try{ 
    //do work... 
    return OK(myResult); 
    } 
    catch(){ 
    return NotFound(); 
    } 
} 

角度サービス:

$http.get('/csuv5.asmx/updcomson', { 
      params: { 
       //params 
      } 
     }) 
     .then(function (response) { 
      // do something with the response 
     },function(error){ 
      // handle error 
     }) 
関連する問題