Ejemplo n.º 1
0
        public IActionResult createBooking(BookingDermagaHeader DermagaHeader)
        {
            BookingDermagaDL execute = new BookingDermagaDL();

            return(Ok(execute.createBooking(DermagaHeader)));
        }
Ejemplo n.º 2
0
        public Dictionary <String, String> createBooking(BookingDermagaHeader DermagaHeader)
        {
            Dictionary <String, String> result = new Dictionary <string, string>();

            using (IDbConnection connection = Extension.GetConnection(1))
            {
                try
                {
                    var transaction = connection.BeginTransaction();

                    string header = @"INSERT INTO MAGIC_BOOKING_HEADER VALUES('" +
                                    DermagaHeader.booking_id + "', '" +
                                    DermagaHeader.kode_kapal + "', '" +
                                    DermagaHeader.nama_kapal + "', '" +
                                    DermagaHeader.gt + "', '" +
                                    DermagaHeader.loa + "', '" +
                                    DermagaHeader.draft + "', '" +
                                    DermagaHeader.komoditi + "', '" +
                                    DermagaHeader.kd_cabang + "', TO_DATE('" +
                                    DateTime.Now + "', 'MM/DD/YYYY HH:MI:SS AM'), " +
                                    DermagaHeader.lama_rencana_tambat + ", '" +
                                    DermagaHeader.kode_pelabuhan + "', '" +
                                    DermagaHeader.nama_pelabuhan + "', " +
                                    DermagaHeader.kade_awal + ", " + DermagaHeader.kade_akhir + ", '" +
                                    DermagaHeader.kode_pelanggan +
                                    "')";

                    var execute_header = connection.Execute(header, new { booking_id = DermagaHeader.booking_id }, transaction);

                    int[] detail_status = new int[4];
                    int   i             = 0;
                    foreach (var Item in DermagaHeader.dermaga_detail)
                    {
                        string detail = @"INSERT INTO MAGIC_BOOKING_DETAIL VALUES('" +
                                        Item.booking_id + "', '" +
                                        Item.jasa + "', '" +
                                        Item.asal + "', '" +
                                        Item.tujuan + "', TO_DATE('" +
                                        Item.tgl_mulai + "', 'MM/DD/YYYY HH:MI:SS AM'), TO_DATE('" +
                                        Item.tgl_selesai + "', 'MM/DD/YYYY HH:MI:SS AM'), '" +
                                        Item.jam_mulai + "', '" +
                                        Item.jam_selesai + "', " +
                                        Item.jumlah_gerakan + ", '" +
                                        Item.gerakan + "', " +
                                        Item.epb + ", TO_DATE('" +
                                        Item.created_date + "', 'MM/DD/YYYY HH:MI:SS AM'), '" +
                                        Item.kode_pelabuhan_asal + "', '" +
                                        Item.kode_pelabuhan_tujuan + "'" +
                                        ")";

                        var execute_detail = connection.Execute(detail, new { booking_id = Item.booking_id }, transaction);

                        if (execute_detail == 1)
                        {
                            detail_status[i] = 1;
                        }
                        else
                        {
                            detail_status[i] = 0;
                        }

                        i++;
                    }

                    if (execute_header == 1 && detail_status.Contains(0) == false)
                    {
                        transaction.Commit();

                        result.Add("code", "200");
                        result.Add("status", "success");
                        result.Add("message", "Booking berhasil dikirim");
                    }
                    else
                    {
                        transaction.Rollback();

                        result.Add("code", "500");
                        result.Add("status", "error");
                        result.Add("message", "Terjadi kesalahan.");
                    }
                }
                catch (Exception)
                {
                    result.Add("code", "500");
                    result.Add("status", "error");
                    result.Add("message", "Terjadi kesalahan.");
                }
            }

            return(result);
        }