public HttpResponseMessage translate(PaymentOption post, Int32 languageId = 0)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }
            else if (Language.MasterPostExists(languageId) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The language does not exist"));
            }
            else if (PaymentOption.MasterPostExists(post.id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The payment option does not exist"));
            }
            else if (ValueAddedTax.MasterPostExists(post.value_added_tax_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The value added tax does not exist"));
            }

            // Make sure that the data is valid
            post.product_code      = AnnytabDataValidation.TruncateString(post.product_code, 50);
            post.name              = AnnytabDataValidation.TruncateString(post.name, 100);
            post.payment_term_code = AnnytabDataValidation.TruncateString(post.payment_term_code, 10);
            post.fee          = AnnytabDataValidation.TruncateDecimal(post.fee, 0, 9999999999.99M);
            post.account_code = AnnytabDataValidation.TruncateString(post.account_code, 10);

            // Get the post
            PaymentOption savedPost = PaymentOption.GetOneById(post.id, languageId);

            // Check if we should add or update the post
            if (savedPost == null)
            {
                PaymentOption.AddLanguagePost(post, languageId);
            }
            else
            {
                PaymentOption.UpdateLanguagePost(post, languageId);
            }

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The translate was successful"));
        } // End of the translate method
示例#2
0
        public HttpResponseMessage update(Order post)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }
            else if (Company.MasterPostExists(post.company_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The company does not exist"));
            }
            else if (Customer.MasterPostExists(post.customer_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The customer does not exist"));
            }
            else if (Currency.MasterPostExists(post.currency_code) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The currency does not exist"));
            }
            else if (Country.MasterPostExists(post.invoice_country_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The invoice country does not exist"));
            }
            else if (Country.MasterPostExists(post.delivery_country_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The delivery country does not exist"));
            }
            else if (PaymentOption.MasterPostExists(post.payment_option) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The payment option does not exist"));
            }

            // Make sure that the data is valid
            post.order_date            = AnnytabDataValidation.TruncateDateTime(post.order_date);
            post.country_code          = AnnytabDataValidation.TruncateString(post.country_code, 2);
            post.language_code         = AnnytabDataValidation.TruncateString(post.language_code, 2);
            post.currency_code         = AnnytabDataValidation.TruncateString(post.currency_code, 3);
            post.conversion_rate       = AnnytabDataValidation.TruncateDecimal(post.conversion_rate, 0, 9999.999999M);
            post.customer_org_number   = AnnytabDataValidation.TruncateString(post.customer_org_number, 20);
            post.customer_vat_number   = AnnytabDataValidation.TruncateString(post.customer_vat_number, 20);
            post.customer_name         = AnnytabDataValidation.TruncateString(post.customer_name, 100);
            post.customer_phone        = AnnytabDataValidation.TruncateString(post.customer_phone, 100);
            post.customer_mobile_phone = AnnytabDataValidation.TruncateString(post.customer_mobile_phone, 100);
            post.customer_email        = AnnytabDataValidation.TruncateString(post.customer_email, 100);
            post.invoice_name          = AnnytabDataValidation.TruncateString(post.invoice_name, 100);
            post.invoice_address_1     = AnnytabDataValidation.TruncateString(post.invoice_address_1, 100);
            post.invoice_address_2     = AnnytabDataValidation.TruncateString(post.invoice_address_2, 100);
            post.invoice_post_code     = AnnytabDataValidation.TruncateString(post.invoice_post_code, 100);
            post.invoice_city          = AnnytabDataValidation.TruncateString(post.invoice_city, 100);
            post.delivery_name         = AnnytabDataValidation.TruncateString(post.delivery_name, 100);
            post.delivery_address_1    = AnnytabDataValidation.TruncateString(post.delivery_address_1, 100);
            post.delivery_address_2    = AnnytabDataValidation.TruncateString(post.delivery_address_2, 100);
            post.delivery_post_code    = AnnytabDataValidation.TruncateString(post.delivery_post_code, 100);
            post.delivery_city         = AnnytabDataValidation.TruncateString(post.delivery_city, 100);
            post.net_sum                  = AnnytabDataValidation.TruncateDecimal(post.net_sum, 0, 999999999999.99M);
            post.vat_sum                  = AnnytabDataValidation.TruncateDecimal(post.vat_sum, 0, 999999999999.99M);
            post.rounding_sum             = AnnytabDataValidation.TruncateDecimal(post.rounding_sum, -99.999M, 999.999M);
            post.total_sum                = AnnytabDataValidation.TruncateDecimal(post.total_sum, 0, 999999999999.99M);
            post.payment_token            = AnnytabDataValidation.TruncateString(post.payment_token, 50);
            post.payment_status           = AnnytabDataValidation.TruncateString(post.payment_status, 50);
            post.order_status             = AnnytabDataValidation.TruncateString(post.order_status, 50);
            post.desired_date_of_delivery = AnnytabDataValidation.TruncateDateTime(post.desired_date_of_delivery);
            post.discount_code            = AnnytabDataValidation.TruncateString(post.discount_code, 50);
            post.gift_cards_amount        = AnnytabDataValidation.TruncateDecimal(post.gift_cards_amount, 0, 999999999999M);

            // Get the saved post
            Order savedPost = Order.GetOneById(post.id);

            // Check if the post exists
            if (savedPost == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The record does not exist"));
            }

            // Update the post
            Order.Update(post);

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The update was successful"));
        } // End of the update method