Exemple #1
0
        public HttpResponseMessage Put([FromBody] PromotionModel promotionModel)
        {
            try
            {
                if (string.IsNullOrEmpty(promotionModel.PromotionMasterData.promotion_name))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Promotion Name is empty !!"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(promotionModel.PromotionMasterData.promotion_start_date.ToString()))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Promotion Start Date is empty !!"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(promotionModel.PromotionMasterData.promotion_end_date.ToString()))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Promotion End Date is empty !!"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(promotionModel.PromotionMasterData.product_category_id.ToString()))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Please Select Category !!"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(promotionModel.PromotionMasterData.product_id.ToString()))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Please Select Product !!"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(promotionModel.PromotionMasterData.lifting_quantity_for_promotion.ToString()))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Lifting Quantity is empty !!"
                    }, formatter));
                }
                if (promotionModel.PromotionMasterData.lifting_quantity_for_promotion < 1)
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Lifting Quantity is alaways greater than Zero !!"
                    }, formatter));
                }
                if (string.IsNullOrEmpty(promotionModel.PromotionMasterData.promotion_type))
                {
                    var formatter = RequestFormat.JsonFormaterString();
                    return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                        output = "warning", msg = "Promotion Type is empty !!"
                    }, formatter));
                }
                if (promotionModel.PromotionMasterData.promotion_type == "Incentive")
                {
                    if (string.IsNullOrEmpty(promotionModel.PromotionMasterData.promotion_discount.ToString()))
                    {
                        var formatter = RequestFormat.JsonFormaterString();
                        return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                            output = "warning", msg = "Promotion Discount is empty !!"
                        }, formatter));
                    }
                    if (promotionModel.PromotionMasterData.promotion_discount == 0)
                    {
                        var formatter = RequestFormat.JsonFormaterString();
                        return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                            output = "warning", msg = "Promotion Discount is alaways greater than zero !!"
                        }, formatter));
                    }
                    else
                    {
                        var x = promotionRepository.EditPromotion(promotionModel);
                        if (x == 1)
                        {
                            var formatter = RequestFormat.JsonFormaterString();
                            return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                                output = "success", msg = "Promotion updated successfully"
                            }, formatter));
                        }
                        else
                        {
                            var formatter = RequestFormat.JsonFormaterString();
                            return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                                output = "error", msg = "Promotion Update Failed !!!"
                            }, formatter));
                        }
                    }
                }
                if (promotionModel.PromotionMasterData.promotion_type == "Product")
                {
                    if (promotionModel.PromotionDetailsList.Count == 0)
                    {
                        var formatter = RequestFormat.JsonFormaterString();
                        return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                            output = "warning", msg = "Please add new record for promotion !!"
                        }, formatter));
                    }
                    else
                    {
                        var x = promotionRepository.EditPromotion(promotionModel);
                        if (x == 1)
                        {
                            var formatter = RequestFormat.JsonFormaterString();
                            return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                                output = "success", msg = "Promotion Updated successfully"
                            }, formatter));
                        }
                        else
                        {
                            var formatter = RequestFormat.JsonFormaterString();
                            return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                                output = "error", msg = "Promotion Update Failed !!!"
                            }, formatter));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var formatter = RequestFormat.JsonFormaterString();
                return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                    output = "error", msg = ex.ToString()
                }, formatter));
            }
            var xxx = RequestFormat.JsonFormaterString();

            return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                output = "error", msg = "Global Error"
            }, xxx));
        }