public IActionResult AddConstituency(ConstituencyRequestmodel constituencyRequestmodel)
        {
            var user = HttpContext.User;
            ConstituencyResponseModel result = new ConstituencyResponseModel();

            if (user.HasClaim(c => c.Type == "Typetoken"))
            {
                if (user.Claims.FirstOrDefault(c => c.Type == "Typetoken").Value == "Login")
                {
                    result = constituencyBL.AddConstituency(constituencyRequestmodel);
                    if (result != null)
                    {
                        var success = true;
                        var message = "Constituency added";
                        return(Ok(new { success, message, result }));
                    }
                    else
                    {
                        var success = false;
                        var message = "Constituency added failed";
                        return(Ok(new { success, message }));
                    }
                }
            }
            return(BadRequest("Use Invalid Token"));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// This is the method for Get single constituency Record.
 /// </summary>
 /// <param name="constituencyId"></param>
 /// <returns></returns>
 public ConstituencyResponseModel GetConstituencyById(int constituencyId)
 {
     try
     {
         SqlConnection sqlConnection = new SqlConnection(_configuration["connectionstring:ElectionDb"]);
         SqlCommand    sqlCommand    = new SqlCommand("sp_Constituency", sqlConnection);
         sqlCommand.CommandType = CommandType.StoredProcedure;
         sqlCommand.Parameters.AddWithValue("@ConstituencyId", constituencyId);
         sqlCommand.Parameters.AddWithValue("@Query", 5);
         sqlConnection.Open();
         SqlDataReader reader = sqlCommand.ExecuteReader();
         while (reader.Read())
         {
             constituency = new ConstituencyResponseModel();
             constituency.ConstituencyId = Convert.ToInt32(reader["ConstituencyId"]);
             constituency.Name           = reader["Name"].ToString();
             constituency.City           = reader["City"].ToString();
             constituency.State          = reader["State"].ToString();
             constituency.CreatedDate    = Convert.ToDateTime(reader["CreatedDate"]).ToLocalTime();
             constituency.ModifiedDate   = Convert.ToDateTime(reader["ModifiedDate"]).ToLocalTime();
         }
         if (constituency != null)
         {
             return(constituency);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
        public IActionResult GetConstituencyById(int constituencyId)
        {
            var user = HttpContext.User;
            ConstituencyResponseModel result = new ConstituencyResponseModel();

            if (user.HasClaim(c => c.Type == "Typetoken"))
            {
                if (user.Claims.FirstOrDefault(c => c.Type == "Typetoken").Value == "Login")
                {
                    result = constituencyBL.GetConstituencyById(constituencyId);
                    if (result != null)
                    {
                        var success = true;
                        var message = "Getting single record By Id successful";
                        return(Ok(new { success, message, result }));
                    }
                    else
                    {
                        var success = false;
                        var message = "Getting single record By Id failed";
                        return(Ok(new { success, message }));
                    }
                }
            }
            return(BadRequest("Used Invalid Token"));
        }