public IActionResult ValidateOTPLogin([FromBody] OTPValidatorRequest request) { if (!request.ValidateObject()) { try { ExceptionHandeling.FireError((int)ErrorCode.General_Error, (int)GeneralError.Nullable_Request, Constants.Constants.GeneralErrorDic[GeneralError.Nullable_Request]); } catch (CodeLabException codelabExp) { return(ExceptionHandeling.GenerateErrorResponse(codelabExp)); } } OTPValidatorResponse response = new OTPValidatorResponse(); AccountRep accountRep = new AccountRep(Context); Account CurrentAccount = accountRep.GetByMSDIN(request.BasicInfo.MobileNumberInfo.Number); if (CurrentAccount == null) { try { ExceptionHandeling.FireError((int)ErrorCode.Wrong_Input_Error, (int)WrongInputError.Wrong_Wallet_Number, Constants.Constants.WrongInputDic[WrongInputError.Wrong_Wallet_Number]); } catch (CodeLabException codelabExp) { return(ExceptionHandeling.GenerateErrorResponse(codelabExp)); } } OTPRep oTPRep = new OTPRep(Context); bool access = oTPRep.ValidateOTP(request.Otp, CurrentAccount.LastOtpid); if (access == true) { response.Status = 1; response.CurrentBalance = (double)CurrentAccount.Balance; response.AdditionalInfo = "Login successfully with otp " + request.Otp + "\n" + "Basic Info: " + request.BasicInfo.ToString(); } else { try { ExceptionHandeling.FireError((int)ErrorCode.Wrong_Input_Error, (int)WrongInputError.Wrong_Otp, Constants.Constants.WrongInputDic[WrongInputError.Wrong_Otp]); } catch (CodeLabException codelabExp) { return(ExceptionHandeling.GenerateErrorResponse(codelabExp)); } } return(Ok(response)); }
public IActionResult CheckTransactionStatus([FromBody] CheckStatusRequest request) { if (!request.ValidateObject()) { try { ExceptionHandeling.FireError((int)ErrorCode.General_Error, (int)GeneralError.Nullable_Request, Constants.Constants.GeneralErrorDic[GeneralError.Nullable_Request]); } catch (CodeLabException codelabExp) { return(ExceptionHandeling.GenerateErrorResponse(codelabExp)); } } ConfirmPaymentResponse response = new ConfirmPaymentResponse(); TransactionRep transactionRep = new TransactionRep(Context); AccountRep accountRep = new AccountRep(Context); Account account = accountRep.GetByMSDIN(request.BasicInfo.MobileNumberInfo.Number); Transaction transaction = transactionRep.GetByTransactionID(request.TransactionId); //Question try { if (account != null) { if (transaction != null) { response.TransactionStatus = 1; response.AdditionalInfo = "string information" + "\n" + "Basic Info:" + request.BasicInfo.ToString(); response.TransactionId = transaction.TransactionId; response.CurrentBalance = (double)account.Balance; response.CompletionDateTime = transaction.IssueTime.ToString(Constants.Constants.DateTimeFormat); response.TotalAmount = (double)transaction.Amount; response.CurrencyCode = transaction.CurrencyCode; } else { ExceptionHandeling.FireError((int)ErrorCode.Payment_Error, (int)PaymentError.Transaction_Id_Not_Exist, Constants.Constants.PaymentErrorDic[PaymentError.Transaction_Id_Not_Exist]); } } else { ExceptionHandeling.FireError((int)ErrorCode.Wrong_Input_Error, (int)WrongInputError.Wrong_Wallet_Number, Constants.Constants.WrongInputDic[WrongInputError.Wrong_Wallet_Number]); } } catch (CodeLabException codelabExp) { return(ExceptionHandeling.GenerateErrorResponse(codelabExp)); } return(Ok(response)); }
public IActionResult ValidateCredentials([FromBody] LoginRequest request) { if (!request.ValidateObject()) { try { ExceptionHandeling.FireError((int)ErrorCode.General_Error, (int)GeneralError.Nullable_Request, Constants.Constants.GeneralErrorDic[GeneralError.Nullable_Request]); } catch (CodeLabException codelabExp) { return(ExceptionHandeling.GenerateErrorResponse(codelabExp)); } } LoginResponse response = new LoginResponse(); AccountRep accountRep = new AccountRep(Context); int y = ExceptionHandeling.x(); Account CurrentAccount = accountRep.ValidateCorrectCredentials(request.BasicInfo.MobileNumberInfo.Number, request.Password); if (CurrentAccount != null) { response.LoginStatus = 1; response.AdditionalInfo = "Login Success with password " + request.Password + "\n" + "Basic Info: " + request.BasicInfo.ToString(); } else { //List<CodeLabException> allErrors = new List<CodeLabException>(); try { ExceptionHandeling.FireError((int)ErrorCode.Wrong_Input_Error, (int)WrongInputError.Wrong_Wallet_Number_OR_Password, Constants.Constants.WrongInputDic[WrongInputError.Wrong_Wallet_Number_OR_Password]); } catch (CodeLabException codelabExp) { return(ExceptionHandeling.GenerateErrorResponse(codelabExp)); } } return(Ok(response)); }
public IActionResult ValidateCredentials([FromBody] LoginRequest request) { LoginResponse response = new LoginResponse(); AccountRep accountRep = new AccountRep(Context); CurrentAccount = accountRep.ValidateCorrectCredentials(request.BasicInfo.MobileNumberInfo.Number, request.Password); if (CurrentAccount != null) { response.LoginStatus = 1; response.AdditionalInfo = "Login Success with password " + request.Password + "\n" + "Basic Info: " + request.BasicInfo.ToString(); } else { List <CodeLabException> allErrors = new List <CodeLabException>(); try { FireError(); } catch (CodeLabException codelabExp) { allErrors.Add(codelabExp); ObjectResult res = new ObjectResult(allErrors); res.ContentTypes.Add("application/json"); var formatterSettings = JsonSerializerSettingsProvider.CreateSerializerSettings(); formatterSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; JsonOutputFormatter formatter = new JsonOutputFormatter(formatterSettings, ArrayPool <Char> .Create()); res.Formatters.Add(formatter); res.StatusCode = 490; return(res); } } return(Ok(response)); }
public IActionResult PerformTransaction([FromBody] ConfirmPaymentRequest request) { if (!request.ValidateObject()) { try { ExceptionHandeling.FireError((int)ErrorCode.General_Error, (int)GeneralError.Nullable_Request, Constants.Constants.GeneralErrorDic[GeneralError.Nullable_Request]); } catch (CodeLabException codelabExp) { return(ExceptionHandeling.GenerateErrorResponse(codelabExp)); } } ConfirmPaymentResponse response = new ConfirmPaymentResponse(); AccountRep accountRep = new AccountRep(Context); Account fromWallet = accountRep.GetByMSDIN(request.BasicInfo.MobileNumberInfo.Number); Account toWallet = accountRep.GetByMSDIN(request.ToWalletNumber); decimal totalAmount = (decimal)request.TotalAmount; string DecodedMPIN = ""; try { byte[] data = Convert.FromBase64String(request.MPin); DecodedMPIN = Encoding.UTF8.GetString(data); } catch (Exception ex) { DecodedMPIN = ""; } try { if (fromWallet != null && toWallet != null) { if (fromWallet == toWallet) { ExceptionHandeling.FireError((int)ErrorCode.Payment_Error, (int)PaymentError.Same_From_To_Wallet, Constants.Constants.PaymentErrorDic[PaymentError.Same_From_To_Wallet]); } if (fromWallet.Mpin == DecodedMPIN) { if (toWallet.Balance >= totalAmount) { if (request.TotalAmount <= Constants.Constants.MaxLimit) { if (request.TotalAmount >= Constants.Constants.MinLimit) { fromWallet.Balance -= totalAmount; toWallet.Balance += totalAmount; accountRep.Update(fromWallet); accountRep.Update(toWallet); //insert Transaction Transaction transaction = new Transaction() { TransactionId = request.TransactionId, FromAccount = fromWallet.Id, ToAccount = toWallet.Id, Status = 2, IssueTime = DateTime.Now, LastUpdateTime = DateTime.Now, Amount = totalAmount, CurrencyCode = request.CurrencyCode }; TransactionRep transactionRep = new TransactionRep(Context); transactionRep.InsertTransaction(transaction); response.TransactionStatus = 1; response.AdditionalInfo = "string information" + "\n" + "Basic Info:" + request.BasicInfo.ToString();; response.TransactionId = request.TransactionId; response.CurrentBalance = (double)fromWallet.Balance; response.CompletionDateTime = transaction.IssueTime.ToString(Constants.Constants.DateTimeFormat); response.TotalAmount = (double)transaction.Amount; response.CurrencyCode = transaction.CurrencyCode; } else { ExceptionHandeling.FireError((int)ErrorCode.Payment_Error, (int)PaymentError.Less_Than_Min_Amount, Constants.Constants.PaymentErrorDic[PaymentError.Less_Than_Min_Amount]); } } else { ExceptionHandeling.FireError((int)ErrorCode.Payment_Error, (int)PaymentError.Greater_Than_Max_Amount, Constants.Constants.PaymentErrorDic[PaymentError.Greater_Than_Max_Amount]); } } else { ExceptionHandeling.FireError((int)ErrorCode.Payment_Error, (int)PaymentError.Insufficient_Balance, Constants.Constants.PaymentErrorDic[PaymentError.Insufficient_Balance]); } } else { ExceptionHandeling.FireError((int)ErrorCode.Wrong_Input_Error, (int)WrongInputError.Wrong_MPIN, Constants.Constants.WrongInputDic[WrongInputError.Wrong_MPIN]); } } else { ExceptionHandeling.FireError((int)ErrorCode.Wrong_Input_Error, (int)WrongInputError.Wrong_Wallet_Number, Constants.Constants.WrongInputDic[WrongInputError.Wrong_Wallet_Number]); } } catch (CodeLabException codelabExp) { return(ExceptionHandeling.GenerateErrorResponse(codelabExp)); } return(Ok(response)); }
public void FindCriteriaPathInaccessibleValue() { ViewFactory<Order> factory = ViewFactory<Order>.IList(); ObjectListView<Order> view = factory.View; IList<Order> list = factory.List; Company acme = new Company("Acme", "Seattle", "WA"); Company ajax = new Company("Ajax", "Detroit", "MI"); AccountRep steve = new AccountRep("Steve O'Donnell", 56); AccountRep carol = new AccountRep("Carol Hanson", 12); AccountRep john = new AccountRep("John Roche", 12); Customer bob = new Customer("Bob Smith", acme, steve); Customer tom = new Customer("Tom Kelly", ajax, carol); Customer mike = new Customer("Mike Palooza", acme, john); Customer rick = new Customer("Rick Doohan", ajax, null); list.Add(new Order(rick, "Glue", 15)); list.Add(new Order(bob, "Widgets", 10)); list.Add(new Order(bob, "Nails", 200)); list.Add(new Order(tom, "Boxes", 20)); list.Add(new Order(tom, "Gadgets", 7)); list.Add(new Order(mike, "Bolts", 3000)); int firstIndex = view.Find("Customer.AccountRep.Department = 12 AND Customer.AccountRep.Name = Carol*"); Assert.AreEqual(3, firstIndex); }
public void SortPropertyPath() { ViewFactory<Order> factory = ViewFactory<Order>.IList(); ObjectListView<Order> view = factory.View; IList<Order> list = factory.List; Company acme = new Company("Acme", "Seattle", "WA"); Company ajax = new Company("Ajax", "Detroit", "MI"); AccountRep steve = new AccountRep("Steve O'Donnell", 56); AccountRep carol = new AccountRep("Carol Hanson", 12); AccountRep john = new AccountRep("John Roche", 10); Customer bob = new Customer("Bob Smith", acme, steve); Customer tom = new Customer("Tom Kelly", ajax, carol); Customer mike = new Customer("Mike Palooza", acme, john); list.Add(new Order(bob, "Widgets", 10)); list.Add(new Order(bob, "Nails", 200)); list.Add(new Order(tom, "Boxes", 20)); list.Add(new Order(tom, "Gadgets", 7)); list.Add(new Order(mike, "Bolts", 3000)); // Sort should be: // Bolts // Boxes // Gadgets // Widgets // Nails view.Sort = "Customer.AccountRep.Department ASC"; Assert.AreEqual(5, view.Count); Assert.AreEqual("Bolts", view[0].Product); Assert.AreEqual("Boxes", view[1].Product); Assert.AreEqual("Gadgets", view[2].Product); Assert.AreEqual("Widgets", view[3].Product); Assert.AreEqual("Nails", view[4].Product); }
public void SortPropertyPathInaccessibleValues() { ViewFactory<Order> factory = ViewFactory<Order>.IList(); ObjectListView<Order> view = factory.View; IList<Order> list = factory.List; Company acme = new Company("Acme", "Seattle", "WA"); Company ajax = new Company("Ajax", "Detroit", "MI"); AccountRep steve = new AccountRep("Steve O'Donnell", 56); AccountRep carol = new AccountRep("Carol Hanson", 12); AccountRep john = new AccountRep("John Roche", 10); Customer bob = new Customer("Bob Smith", acme, steve); Customer tom = new Customer("Tom Kelly", ajax, null); Customer mike = new Customer("Mike Palooza", acme, carol); Customer rick = new Customer("Rick Doohan", ajax, john); list.Add(new Order(bob, "Widgets", 10)); list.Add(new Order(bob, "Nails", 200)); list.Add(new Order(tom, "Boxes", 20)); list.Add(new Order(tom, "Gadgets", 7)); list.Add(new Order(mike, "Bolts", 3000)); list.Add(new Order(rick, "Glue", 15)); // Sort should be: // (note that the items that compare equally will be sorted in reverse of list order because the sort direction is descending) // Nails // Widgets // Bolts // Glue // Gadgets // Boxes view.Sort = "Customer.AccountRep.Department DESC"; Assert.AreEqual(6, view.Count); Assert.AreEqual("Nails", view[0].Product); Assert.AreEqual("Widgets", view[1].Product); Assert.AreEqual("Bolts", view[2].Product); Assert.AreEqual("Glue", view[3].Product); Assert.AreEqual("Gadgets", view[4].Product); Assert.AreEqual("Boxes", view[5].Product); }
public void SelectCriteriaPath() { ViewFactory<Order> factory = ViewFactory<Order>.IList(); ObjectListView<Order> view = factory.View; IList<Order> list = factory.List; Company acme = new Company("Acme", "Seattle", "WA"); Company ajax = new Company("Ajax", "Detroit", "MI"); AccountRep steve = new AccountRep("Steve O'Donnell", 56); AccountRep carol = new AccountRep("Carol Hanson", 12); AccountRep john = new AccountRep("John Roche", 12); Customer bob = new Customer("Bob Smith", acme, steve); Customer tom = new Customer("Tom Kelly", ajax, carol); Customer mike = new Customer("Mike Palooza", acme, john); list.Add(new Order(bob, "Widgets", 10)); list.Add(new Order(bob, "Nails", 200)); list.Add(new Order(tom, "Boxes", 20)); list.Add(new Order(tom, "Gadgets", 7)); list.Add(new Order(mike, "Bolts", 3000)); IList<Order> matches = view.Select("Customer.AccountRep.Department = 12 AND Customer.AccountRep.Name = Carol*"); Assert.IsNotNull(matches); Assert.AreEqual(2, matches.Count); Assert.AreEqual("Boxes", matches[0].Product); Assert.AreEqual("Gadgets", matches[1].Product); }
public void FilterPathInaccessibleValue() { ViewFactory<Order> factory = ViewFactory<Order>.IList(); ObjectListView<Order> view = factory.View; IList<Order> list = factory.List; Company acme = new Company("Acme", "Seattle", "WA"); Company ajax = new Company("Ajax", "Detroit", "MI"); AccountRep steve = new AccountRep("Steve O'Donnell", 56); AccountRep carol = new AccountRep("Carol Hanson", 12); AccountRep john = new AccountRep("John Roche", 12); Customer bob = new Customer("Bob Smith", acme, steve); Customer tom = new Customer("Tom Kelly", ajax, carol); Customer mike = new Customer("Mike Palooza", acme, john); Customer rick = new Customer("Rick Doohan", ajax, null); list.Add(new Order(bob, "Widgets", 10)); list.Add(new Order(bob, "Nails", 200)); list.Add(new Order(tom, "Boxes", 20)); list.Add(new Order(tom, "Gadgets", 7)); list.Add(new Order(mike, "Bolts", 3000)); list.Add(new Order(rick, "Glue", 15)); // Rick's order should be excluded because there is no AccountRep. view.Filter = "Customer.AccountRep.Department = 12"; Assert.AreEqual(3, view.Count); Assert.AreEqual("Boxes", view[0].Product); Assert.AreEqual("Gadgets", view[1].Product); Assert.AreEqual("Bolts", view[2].Product); }
public void FilterPathInvalid() { ViewFactory<Order> factory = ViewFactory<Order>.IList(); ObjectListView<Order> view = factory.View; IList<Order> list = factory.List; Company acme = new Company("Acme", "Seattle", "WA"); Company ajax = new Company("Ajax", "Detroit", "MI"); AccountRep steve = new AccountRep("Steve O'Donnell", 56); AccountRep carol = new AccountRep("Carol Hanson", 12); AccountRep john = new AccountRep("John Roche", 12); Customer bob = new Customer("Bob Smith", acme, steve); Customer tom = new Customer("Tom Kelly", ajax, carol); Customer mike = new Customer("Mike Palooza", acme, john); list.Add(new Order(bob, "Widgets", 10)); list.Add(new Order(bob, "Nails", 200)); list.Add(new Order(tom, "Boxes", 20)); list.Add(new Order(tom, "Gadgets", 7)); list.Add(new Order(mike, "Bolts", 3000)); view.Filter = "Customer.Rank = 12"; }
public void FilterValuesChanged() { ViewFactory<Order> factory = ViewFactory<Order>.IBindingList(); ObjectListView<Order> view = factory.View; IList<Order> list = factory.List; Company acme = new Company("Acme", "Seattle", "WA"); Company ajax = new Company("Ajax", "Detroit", "MI"); AccountRep steve = new AccountRep("Steve O'Donnell", 56); AccountRep carol = new AccountRep("Carol Hanson", 12); AccountRep john = new AccountRep("John Roche", 12); Customer bob = new Customer("Bob Smith", acme, steve); Customer tom = new Customer("Tom Kelly", ajax, carol); Customer mike = new Customer("Mike Palooza", acme, john); list.Add(new Order(bob, "Widgets", 10)); list.Add(new Order(bob, "Nails", 200)); list.Add(new Order(tom, "Boxes", 20)); list.Add(new Order(tom, "Gadgets", 7)); list.Add(new Order(mike, "Bolts", 3000)); view.Filter = "Quantity > 20"; Assert.AreEqual(2, view.Count); list[0].Quantity = 100; Assert.AreEqual(3, view.Count); Assert.AreEqual("Widgets", view[0].Product); Assert.AreEqual("Nails", view[1].Product); Assert.AreEqual("Bolts", view[2].Product); }
public void FilterPathNonPublicProperty() { ViewFactory<Order> factory = ViewFactory<Order>.IList(); ObjectListView<Order> view = factory.View; IList<Order> list = factory.List; Company acme = new Company("Acme", "Seattle", "WA"); Company ajax = new Company("Ajax", "Detroit", "MI"); AccountRep steve = new AccountRep("Steve O'Donnell", 56); AccountRep carol = new AccountRep("Carol Hanson", 12); AccountRep john = new AccountRep("John Roche", 12); Customer bob = new Customer("Bob Smith", acme, steve); Customer tom = new Customer("Tom Kelly", ajax, carol); Customer mike = new Customer("Mike Palooza", acme, john); Customer rick = new Customer("Rick Doohan", ajax, null); list.Add(new Order(bob, "Widgets", 10)); list.Add(new Order(bob, "Nails", 200)); list.Add(new Order(tom, "Boxes", 20)); list.Add(new Order(tom, "Gadgets", 7)); list.Add(new Order(mike, "Bolts", 3000)); list.Add(new Order(rick, "Glue", 15)); // SSN is protected. view.Filter = "Customer.AccountRep.SSN = 123456789"; }