コード例 #1
0
        public int Add(CheckoutAddRequest model, int userId)
        {
            int id = 0;

            Guid guid = Guid.NewGuid();

            string procName = "[dbo].[Checkout_Orders_Insert]";

            _data.ExecuteNonQuery(procName,
                                  inputParamMapper : delegate(SqlParameterCollection col)
            {
                AddCommonParams(model, col);
                col.AddWithValue("@CreatedBy", userId);
                col.AddWithValue("@TrackingUrl", guid);
                SqlParameter idOut = new SqlParameter("@Id", SqlDbType.Int);
                idOut.Direction    = ParameterDirection.Output;

                col.Add(idOut);
            },
                                  returnParameters : delegate(SqlParameterCollection returnCollection)
            {
                object oId = returnCollection["@Id"].Value;

                Int32.TryParse(oId.ToString(), out id);
            });
            return(id);
        }
コード例 #2
0
 private static void AddCommonParams(CheckoutAddRequest model, SqlParameterCollection col)
 {
     col.AddWithValue("@Total", model.Total);
     col.AddWithValue("@TrackingCode", model.TrackingCode);
     col.AddWithValue("@ShippingAddressId", model.ShippingAddressId);
     col.AddWithValue("@ChargeId", model.ChargeId);
     col.AddWithValue("@PaymentAccountId", model.PaymentAccountId);
     col.AddWithValue("@InventoryId", model.InventoryId);
     col.AddWithValue("@Quantity", model.Quantity);
 }
コード例 #3
0
ファイル: CheckoutApiController.cs プロジェクト: jtomas2/.NET
        public ActionResult <ItemResponse <int> > Create(CheckoutAddRequest model)
        {
            ObjectResult result = null;
            int          userId = _authService.GetCurrentUserId();

            try
            {
                int id = _service.Add(model, userId);
                ItemResponse <int> response = new ItemResponse <int>()
                {
                    Item = id
                };
                result = Created201(response);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                ErrorResponse response = new ErrorResponse($"Generic Error: {ex.Message}");
                result = StatusCode(500, response);
            }

            return(result);
        }