Beispiel #1
0
        public IHttpActionResult AddSettlementPayment(SettlementPayment payment)
        {
            SettlementPaymentResponse response = new SettlementPaymentResponse();

            try
            {
                payment.User = CurrentUserId;
                SettlementPayment paymentSaved = settlementBL.AddSettlementPayment(payment);
                response.Payment = paymentSaved;
                response.Success = true;
            }
            catch (SettlementException ex)
            {
                response.ErrorCode    = ex.Error;
                response.ErrorMessage = "Error. " + ex.Error.ToString();
                response.Payment      = null;
                response.Success      = false;
            }
            catch (Exception ex)
            {
                response.ErrorMessage = "Error. " + ex.Message;
                response.Payment      = null;
                response.Success      = false;
            }
            return(Ok(response));
        }
Beispiel #2
0
 public SettlementPayment AddSettlementPayment(SettlementPayment payment)
 {
     using (SqlCommand command = new SqlCommand())
     {
         using (SqlConnection connection = new SqlConnection())
         {
             connection.ConnectionString = ConnectionString;
             command.Connection          = connection;
             command.CommandText         = "spUpsertSettlementPayment";
             command.CommandType         = CommandType.StoredProcedure;
             foreach (PropertyInfo prop in (from x in payment.GetType().GetProperties() where !excludedPropertiesInInsert.Contains(x.Name) select x).ToArray())
             {
                 if (prop.PropertyType == typeof(DateTime))
                 {
                     command.Parameters.AddWithValue("@" + prop.Name, ((DateTime)prop.GetValue(payment)).ToUniversalTime());
                 }
                 else if (prop.PropertyType == typeof(DateTime?) && ((DateTime?)prop.GetValue(payment)).HasValue)
                 {
                     command.Parameters.AddWithValue("@" + prop.Name, ((DateTime)prop.GetValue(payment)).ToUniversalTime());
                 }
                 else
                 {
                     command.Parameters.AddWithValue("@" + prop.Name, prop.GetValue(payment));
                 }
             }
             connection.Open();
             object settlementId = command.ExecuteScalar();
             payment.Id = int.Parse(settlementId.ToString());
             connection.Close();
         }
         return(payment);
     }
 }
Beispiel #3
0
        public void TestAddAndRemovePayment()
        {
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
            SettlementPayment    payment = new SettlementPayment();
            int settlementId             = InsertDummySettlement();

            payment.SettlementId   = settlementId;
            payment.Description    = "Test description";
            payment.CheckOrVoucher = "101";
            payment.Date           = DateTime.Now;
            payment.PaymentType    = PaymentType.Cash;
            payment.Total          = 100;
            payment.User           = "******"; //Assume we have a user with this ID
            string     jsonSettlement = javaScriptSerializer.Serialize(payment);
            HttpClient client         = new HttpClient();

            client.BaseAddress = new Uri(baseUrl);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token);
            SettlementPaymentResponse settlementPaymentResponse = new SettlementPaymentResponse();
            //Add payment
            HttpResponseMessage response = client.PostAsJsonAsync(insertPaymentAction, payment).Result;

            Assert.IsTrue(response.IsSuccessStatusCode);
            settlementPaymentResponse = response.Content.ReadAsAsync <SettlementPaymentResponse>().Result;
            Assert.IsTrue(settlementPaymentResponse.Success);
            Assert.IsTrue(settlementPaymentResponse.Payment.Id > 0);
            //Get payments for settlement
            GetSettlementPaymentResponse getSettlementPaymentResponse = new GetSettlementPaymentResponse();
            string getAction = string.Format("{0}?settlementId={1}", getPaymentsAction, settlementId);

            response = client.GetAsync(getAction).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            getSettlementPaymentResponse = response.Content.ReadAsAsync <GetSettlementPaymentResponse>().Result;
            Assert.IsTrue(getSettlementPaymentResponse.Success);
            Assert.IsTrue(getSettlementPaymentResponse.Payments.Count > 0);
            //Remove all payments
            //Test delete
            response = client.PostAsJsonAsync(removePaymentsAction, new IdModel(settlementId)).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            settlementPaymentResponse = response.Content.ReadAsAsync <SettlementPaymentResponse>().Result;
            Assert.IsTrue(settlementPaymentResponse.Success);
            //Get payments, expecting 0
            getSettlementPaymentResponse = new GetSettlementPaymentResponse();
            response = client.GetAsync(getAction).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            getSettlementPaymentResponse = response.Content.ReadAsAsync <GetSettlementPaymentResponse>().Result;
            Assert.IsTrue(getSettlementPaymentResponse.Success);
            Assert.IsTrue(getSettlementPaymentResponse.Payments.Count == 0);
            //delete the dummy settlement
            response = client.PostAsJsonAsync(deleteAction, new IdModel(settlementId)).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            SettlementResponse settlementResponse = response.Content.ReadAsAsync <SettlementResponse>().Result;

            Assert.IsTrue(response.IsSuccessStatusCode);
        }
Beispiel #4
0
 public SettlementPayment AddSettlementPayment(SettlementPayment payment)
 {
     return(settlementDL.AddSettlementPayment(payment));
 }