public void TryingToAddANullPromotion_Throws_ArgumentNullException()
        {
            // Act
            Action act = () => _sut.AddPromotion(null);

            // Assert
            act.Should().Throw <ArgumentNullException>();
        }
예제 #2
0
        public async Task <ActionResult> Create(bool sendToAll, PromotionDto promotion)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Create"));
            }
            try
            {
                var result = await _promo.AddPromotion(promotion, sendToAll);

                if (result.Item1)
                {
                    if (result.Item2)
                    {
                        ViewData["Mail"] = "Success";
                    }
                    else
                    {
                        ViewData["Mail"] = "Failure";
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                return(RedirectToAction("Create"));
            }
            catch
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
        public IActionResult Create(Promotion promotion)
        {
            if (ModelState.IsValid)
            {
                _promotionRepository.AddPromotion(promotion);
                return(RedirectToAction(nameof(Index)));
            }

            return(View(promotion));
        }
예제 #4
0
        public IActionResult AddPromotion([FromBody] AddPromotionViewModel viewModel)
        {
            var promotion = new Promotion
            {
                Name = viewModel.Name
            };

            try
            {
                return(Ok(_promotionRepository.AddPromotion(promotion, viewModel.StoreId)));
            }
            catch (PromotionException e)
            {
                return(BadRequest(new { message = e.Message }));
            }
        }
예제 #5
0
        public HttpResponseMessage Post([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.AddPromotion(promotionModel);
                        if (x == 1)
                        {
                            var formatter = RequestFormat.JsonFormaterString();
                            return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                                output = "success", msg = "Promotion save successfully"
                            }, formatter));
                        }
                        else
                        {
                            var formatter = RequestFormat.JsonFormaterString();
                            return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                                output = "error", msg = "Error in Promotion !!!"
                            }, 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.AddPromotion(promotionModel);
                        if (x == 1)
                        {
                            var formatter = RequestFormat.JsonFormaterString();
                            return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                                output = "success", msg = "Promotion save successfully"
                            }, formatter));
                        }
                        else
                        {
                            var formatter = RequestFormat.JsonFormaterString();
                            return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                                output = "error", msg = "Error in Promotion !!!"
                            }, 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));
        }