public async Task <long> PostAsync(string tenant, ViewModels.Sales model) { string connectionString = FrapidDbServer.GetConnectionString(tenant); string sql = @"SELECT * FROM sales.post_sales ( @OfficeId::integer, @UserId::integer, @LoginId::bigint, @CounterId::integer, @ValueDate::date, @BookDate::date, @CostCenterId::integer, @ReferenceNumber::national character varying(24), @StatementReference::text, @Tender::public.money_strict2, @Change::public.money_strict2, @PaymentTermId::integer, @CheckAmount::public.money_strict2, @CheckBankName::national character varying(1000), @CheckNumber::national character varying(100), @CheckDate::date, @GiftCardNumber::national character varying(100), @CustomerId::integer, @PriceTypeId::integer, @ShipperId::integer, @StoreId::integer, @CouponCode::national character varying(100), @IsFlatDiscount::boolean, @Discount::public.money_strict2, ARRAY[{0}], @SalesQuotationId::bigint, @SalesOrderId::bigint, @SerialNumberIds::text );"; sql = string.Format(sql, this.GetParametersForDetails(model.Details)); using (var connection = new NpgsqlConnection(connectionString)) { using (var command = new NpgsqlCommand(sql, connection)) { command.Parameters.AddWithNullableValue("@OfficeId", model.OfficeId); command.Parameters.AddWithNullableValue("@UserId", model.UserId); command.Parameters.AddWithNullableValue("@LoginId", model.LoginId); command.Parameters.AddWithNullableValue("@CounterId", model.CounterId); command.Parameters.AddWithNullableValue("@ValueDate", model.ValueDate); command.Parameters.AddWithNullableValue("@BookDate", model.BookDate); command.Parameters.AddWithNullableValue("@CostCenterId", model.CostCenterId); command.Parameters.AddWithNullableValue("@ReferenceNumber", model.ReferenceNumber.Or("")); command.Parameters.AddWithNullableValue("@StatementReference", model.StatementReference.Or("")); command.Parameters.AddWithNullableValue("@Tender", model.Tender); command.Parameters.AddWithNullableValue("@Change", model.Change); command.Parameters.AddWithNullableValue("@PaymentTermId", model.PaymentTermId); command.Parameters.AddWithNullableValue("@CheckAmount", model.CheckAmount); command.Parameters.AddWithNullableValue("@CheckBankName", model.CheckBankName.Or("")); command.Parameters.AddWithNullableValue("@CheckNumber", model.CheckNumber.Or("")); command.Parameters.AddWithNullableValue("@CheckDate", model.CheckDate); command.Parameters.AddWithNullableValue("@GiftCardNumber", model.GiftCardNumber.Or("")); command.Parameters.AddWithNullableValue("@CustomerId", model.CustomerId); command.Parameters.AddWithNullableValue("@PriceTypeId", model.PriceTypeId); command.Parameters.AddWithNullableValue("@ShipperId", model.ShipperId); command.Parameters.AddWithNullableValue("@StoreId", model.StoreId); command.Parameters.AddWithNullableValue("@CouponCode", model.CouponCode.Or("")); command.Parameters.AddWithNullableValue("@IsFlatDiscount", model.IsFlatDiscount); command.Parameters.AddWithNullableValue("@Discount", model.Discount); command.Parameters.AddWithNullableValue("@SalesQuotationId", model.SalesQuotationId); command.Parameters.AddWithNullableValue("@SalesOrderId", model.SalesOrderId); command.Parameters.AddWithNullableValue("@SerialNumberIds", model.SerialNumberIds); command.Parameters.AddRange(this.AddParametersForDetails(model.Details).ToArray()); connection.Open(); var awaiter = await command.ExecuteScalarAsync().ConfigureAwait(false); return(awaiter.To <long>()); } } }
public async Task <ActionResult> PostAsync(ViewModels.Sales model) { if (!this.ModelState.IsValid) { return(this.InvalidModelState(this.ModelState)); } var meta = await AppUsers.GetCurrentAsync().ConfigureAwait(true); model.UserId = meta.UserId; model.OfficeId = meta.OfficeId; model.LoginId = meta.LoginId; try { long tranId = await SalesEntries.PostAsync(this.Tenant, model).ConfigureAwait(true); return(this.Ok(tranId)); } catch (Exception ex) { return(this.Failed(ex.Message, HttpStatusCode.InternalServerError)); } }
public async Task <long> PostAsync(string tenant, ViewModels.Sales model) { string connectionString = FrapidDbServer.GetConnectionString(tenant); const string sql = @"EXECUTE sales.post_sales @OfficeId, @UserId, @LoginId, @CounterId, @ValueDate, @BookDate, @CostCenterId, @ReferenceNumber, @StatementReference, @Tender, @Change, @PaymentTermId, @CheckAmount, @CheckBankName, @CheckNumber, @CheckDate, @GiftCardNumber, @CustomerId, @PriceTypeId, @ShipperId, @StoreId, @CouponCode, @IsFlatDiscount, @Discount, @Details, @SalesQuotationId, @SalesOrderId, @SerialNumberIds, @TransactionMasterId OUTPUT;"; using (var connection = new SqlConnection(connectionString)) { using (var command = new SqlCommand(sql, connection)) { command.Parameters.AddWithNullableValue("@OfficeId", model.OfficeId); command.Parameters.AddWithNullableValue("@UserId", model.UserId); command.Parameters.AddWithNullableValue("@LoginId", model.LoginId); command.Parameters.AddWithNullableValue("@CounterId", model.CounterId); command.Parameters.AddWithNullableValue("@ValueDate", model.ValueDate); command.Parameters.AddWithNullableValue("@BookDate", model.BookDate); command.Parameters.AddWithNullableValue("@CostCenterId", model.CostCenterId); command.Parameters.AddWithNullableValue("@ReferenceNumber", model.ReferenceNumber.Or("")); command.Parameters.AddWithNullableValue("@StatementReference", model.StatementReference.Or("")); command.Parameters.AddWithNullableValue("@Tender", model.Tender); command.Parameters.AddWithNullableValue("@Change", model.Change); command.Parameters.AddWithNullableValue("@PaymentTermId", model.PaymentTermId); command.Parameters.AddWithNullableValue("@CheckAmount", model.CheckAmount); command.Parameters.AddWithNullableValue("@CheckBankName", model.CheckBankName.Or("")); command.Parameters.AddWithNullableValue("@CheckNumber", model.CheckNumber.Or("")); command.Parameters.AddWithNullableValue("@CheckDate", model.CheckDate); command.Parameters.AddWithNullableValue("@GiftCardNumber", model.GiftCardNumber.Or("")); command.Parameters.AddWithNullableValue("@CustomerId", model.CustomerId); command.Parameters.AddWithNullableValue("@PriceTypeId", model.PriceTypeId); command.Parameters.AddWithNullableValue("@ShipperId", model.ShipperId); command.Parameters.AddWithNullableValue("@StoreId", model.StoreId); command.Parameters.AddWithNullableValue("@CouponCode", model.CouponCode.Or("")); command.Parameters.AddWithNullableValue("@IsFlatDiscount", model.IsFlatDiscount); command.Parameters.AddWithNullableValue("@Discount", model.Discount); command.Parameters.AddWithNullableValue("@SalesQuotationId", model.SalesQuotationId); command.Parameters.AddWithNullableValue("@SalesOrderId", model.SalesOrderId); command.Parameters.AddWithNullableValue("@SerialNumberIds", model.SerialNumberIds); using (var details = this.GetDetails(model.Details)) { command.Parameters.AddWithNullableValue("@Details", details, "sales.sales_detail_type"); } command.Parameters.Add("@TransactionMasterId", SqlDbType.BigInt).Direction = ParameterDirection.Output; connection.Open(); await command.ExecuteNonQueryAsync().ConfigureAwait(false); return(command.Parameters["@TransactionMasterId"].Value.To <long>()); } } }
public static async Task <long> PostAsync(string tenant, ViewModels.Sales model) { var entry = LocateService(tenant); return(await entry.PostAsync(tenant, model).ConfigureAwait(false)); }