public JsonResult AjaxAddLineItem(CreateLineItemDto newOrder, ICreateService service)
        {
            if (!ModelState.IsValid)
            {
                //model errors so return errors
                return ModelState.ReturnModelErrorsAsJson();
            }

            var response = service.Create(newOrder);
            if (response.IsValid)
            {
                return Json(new { SuccessMessage = response.SuccessMessage });
            }

            //else errors, so send back the errors
            return response.ReturnErrorsAsJson(newOrder);
        }
Example #2
0
        public JsonResult AjaxAddLineItem(CreateLineItemDto newOrder, ICreateService service)
        {
            if (!ModelState.IsValid)
            {
                //model errors so return errors
                return(ModelState.ReturnModelErrorsAsJson());
            }

            var response = service.Create(newOrder);

            if (response.IsValid)
            {
                return(Json(new { SuccessMessage = response.SuccessMessage }));
            }

            //else errors, so send back the errors
            return(response.ReturnErrorsAsJson(newOrder));
        }
        //----------------------------------

        private CreateLineItemDto AddLineItem(AdventureWorksLt2012 db, short quantity = 1)
        {
            var service  = new CreateService(db);
            var newOrder = new CreateLineItemDto
            {
                SalesOrderID = _salesOrderId,
                CustomerID   = _customerId,
                ProductID    = _productToUse.ProductID,
                OrderQty     = quantity
            };

            //ATTEMPT
            var status = service.Create(newOrder);

            //VERIFY
            status.ShouldBeValid();
            return(newOrder);
        }
        //----------------------------------
        private CreateLineItemDto AddLineItem(AdventureWorksLt2012 db, short quantity = 1)
        {
            var service = new CreateService(db);
            var newOrder = new CreateLineItemDto
            {
                SalesOrderID = _salesOrderId,
                CustomerID = _customerId,
                ProductID = _productToUse.ProductID,
                OrderQty = quantity
            };

            //ATTEMPT
            var status = service.Create(newOrder);

            //VERIFY
            status.ShouldBeValid();
            return newOrder;
        }