public CardDetails GetCardSerialNumber(string loggedInUsername)
        {
            var pd = new CardDetails();

            try
            {
                if (!string.IsNullOrEmpty(loggedInUsername))
                {
                    var details = CardPL.GetCardSerialNumber(loggedInUsername);

                    if (details == null)
                    {
                        pd.response = String.Format("{0}|{1}", "Failed", "No available card serial number.");
                    }
                    else
                    {
                        pd          = details;
                        pd.response = String.Format("{0}|{1}", "Success", "Card serial number exists.");
                    }
                }
                else
                {
                    pd.response = String.Format("{0}|{1}", "Failed", "Username of the logged in user is required.");
                }
            }
            catch (Exception ex)
            {
                pd.response = String.Format("{0}|{1}", "Failed", ex.Message);
                ErrorHandler.WriteError(ex);
            }

            return(pd);
        }
        public CardDetails RetrieveCardDetails(string cardNumber)
        {
            var pd = new CardDetails();

            try
            {
                if (string.IsNullOrEmpty(cardNumber))
                {
                    pd.response = String.Format("{0}|{1}", "Failed", "Pan has no value.");
                }
                else
                {
                    string hashed_pan = PasswordHash.MD5Hash(cardNumber);

                    var details = CardPL.RetrievePregeneratedCard(hashed_pan);

                    if (details == null)
                    {
                        pd.response = String.Format("{0}|{1}", "Failed", "Pan does not exist.");
                    }
                    else
                    {
                        pd          = details;
                        pd.response = String.Format("{0}|{1}", "Success", "Pan exists.");
                    }
                }
            }
            catch (Exception ex)
            {
                pd.response = String.Format("{0}|{1}", "Failed", ex.Message);
                ErrorHandler.WriteError(ex);
            }

            return(pd);
        }
Example #3
0
 public HttpResponseMessage RetrievePregeneratedCards()
 {
     try
     {
         IEnumerable <CardDetails> pregeneratedCards = CardPL.RetrievePregeneratedCards();
         object returnedPregeneratedCards            = new { data = pregeneratedCards };
         return(Request.CreateResponse(HttpStatusCode.OK, returnedPregeneratedCards));
     }
     catch (Exception ex)
     {
         ErrorHandler.WriteError(ex);
         var response = Request.CreateResponse(HttpStatusCode.BadRequest);
         response.ReasonPhrase = ex.Message;
         return(response);
     }
 }
Example #4
0
 public HttpResponseMessage UploadPregeneratedCards([FromBody] CardModel cardModel)
 {
     try
     {
         long successfulCards = 0;
         bool result          = CardPL.Save(cardModel.CardNumbers.ToList(), cardModel.Branch, out successfulCards);
         if (successfulCards != 0)
         {
             return(result.Equals(true) ? Request.CreateResponse(HttpStatusCode.OK, string.Format("{0} unique pregenerated card(s) uploaded successfully.", successfulCards)) : Request.CreateResponse(HttpStatusCode.BadRequest, "Request failed"));
         }
         else
         {
             var response = Request.CreateResponse(HttpStatusCode.BadRequest, "Batch of card numbers uploaded already.");
             return(response);
         }
     }
     catch (Exception ex)
     {
         ErrorHandler.WriteError(ex);
         var response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
         return(response);
     }
 }