Ejemplo n.º 1
0
        public HttpResponseMessage add(GiftCard post)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }
            else if (Language.MasterPostExists(post.language_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The language does not exist"));
            }
            else if (Currency.MasterPostExists(post.currency_code) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The currency does not exist"));
            }

            // Make sure that the data is valid
            post.id       = AnnytabDataValidation.TruncateString(post.id, 50);
            post.amount   = AnnytabDataValidation.TruncateDecimal(post.amount, 0, 999999999999M);
            post.end_date = AnnytabDataValidation.TruncateDateTime(post.end_date);

            // Check if the gift card exists
            if (GiftCard.MasterPostExists(post.id) == true)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The id already exists"));
            }

            // Add the post
            GiftCard.Add(post);

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been added"));
        } // End of the add method
        public HttpResponseMessage update(OrderGiftCard post)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }
            else if (Order.MasterPostExists(post.order_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The order does not exist"));
            }
            else if (GiftCard.MasterPostExists(post.gift_card_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The gift card does not exist"));
            }

            // Make sure that the data is valid
            post.gift_card_id = AnnytabDataValidation.TruncateString(post.gift_card_id, 50);
            post.amount       = AnnytabDataValidation.TruncateDecimal(post.amount, 0, 999999999999M);

            // Get the saved post
            OrderGiftCard savedPost = OrderGiftCard.GetOneById(post.order_id, post.gift_card_id);

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

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

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