Beispiel #1
0
        public HttpResponseMessage Post(afs_shipment_expense post_afs_shipment_expense)
        {
            try
            {
                using (var context = new SAPContext())
                {
                    afs_shipment_expense data = new afs_shipment_expense();
                    data.CLIENT          = post_afs_shipment_expense.CLIENT;
                    data.SHIPMENT_NUMBER = post_afs_shipment_expense.SHIPMENT_NUMBER;
                    data.EXPENSE_ID      = post_afs_shipment_expense.EXPENSE_ID;
                    data.EXPENSE_AMOUNT  = post_afs_shipment_expense.EXPENSE_AMOUNT;
                    data.REMARK          = post_afs_shipment_expense.REMARK;
                    data.CREATED_BY      = post_afs_shipment_expense.CREATED_BY;
                    data.CREATED_DATE    = DateTime.Now;
                    data.UPDATE_BY       = post_afs_shipment_expense.UPDATE_BY;
                    data.UPDATE_DATE     = DateTime.Now;
                    context.afs_shipment_expense.Add(data);
                    context.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK, data));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Beispiel #2
0
 public HttpResponseMessage GetById(afs_shipment_expense postdata)
 {
     try
     {
         using (var context = new SAPContext())
         {
             var afs_shipment_expense = context.afs_shipment_expense.Where(t => t.CLIENT == postdata.CLIENT && t.SHIPMENT_NUMBER == postdata.SHIPMENT_NUMBER).FirstOrDefault();
             return(afs_shipment_expense == null
                 ? Request.CreateErrorResponse(HttpStatusCode.NotFound, "afs_shipment_expense not found")
                 : Request.CreateResponse(HttpStatusCode.OK, afs_shipment_expense));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Beispiel #3
0
        public HttpResponseMessage Delete(afs_shipment_expense postdata)
        {
            try
            {
                using (var context = new SAPContext())
                {
                    var existing = context.afs_shipment_expense.Where(t => t.CLIENT == postdata.CLIENT && t.SHIPMENT_NUMBER == postdata.SHIPMENT_NUMBER).FirstOrDefault();
                    if (existing == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "afs_shipment_expense not found"));
                    }

                    context.afs_shipment_expense.Remove(existing);
                    context.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        public HttpResponseMessage Save(ShipmentDetailModel postdata)
        {
            try
            {
                using (var context = new SAPContext())
                {
                    var            newdata    = false;
                    afs_shipment_h data       = new afs_shipment_h();
                    var            shipment_h = context.afs_shipment_h
                                                .Where(t => t.CLIENT == postdata.client && t.SHIPMENT_NUMBER == postdata.shipment_number).FirstOrDefault();
                    if (shipment_h == null)
                    {
                        newdata                    = true;
                        shipment_h                 = new afs_shipment_h();
                        shipment_h.CLIENT          = postdata.client;
                        shipment_h.SHIPMENT_NUMBER = postdata.shipment_number;
                        shipment_h.CREATED_BY      = postdata.created_by;
                        shipment_h.CREATED_DATE    = DateTime.Now;
                    }

                    shipment_h.TRANSPORT_DATE = DateTime.ParseExact(postdata.transport_date, "dd/MM/yyyy", null);
                    shipment_h.CARGROUP_CODE  = postdata.cargroup_code;
                    shipment_h.DRIVER_ID      = postdata.driver_id;
                    shipment_h.STAFF1_ID      = postdata.staff1_id;
                    shipment_h.STAFF2_ID      = postdata.staff2_id;
                    shipment_h.STATUS         = postdata.status_code;
                    shipment_h.REMARK         = postdata.remark;
                    shipment_h.POINT_ID       = postdata.point_id;
                    shipment_h.UPDATE_BY      = postdata.update_by;
                    shipment_h.UPDATE_DATE    = DateTime.Now;

                    if (newdata)
                    {
                        context.afs_shipment_h.Add(shipment_h);
                    }
                    else
                    {
                        context.Entry(shipment_h).State = EntityState.Modified;
                    }

                    // Save Shipment carries
                    if (postdata.shipment_carries != null)
                    {
                        foreach (var item in postdata.shipment_carries)
                        {
                            newdata = false;
                            var exists = context.afs_shipment_carries.Where(w =>
                                                                            w.CLIENT == item.client &&
                                                                            w.SHIPMENT_NUMBER == item.shipment_number &&
                                                                            w.ITEM_NO == item.itemno).FirstOrDefault();
                            if (exists == null)
                            {
                                newdata                = true;
                                exists                 = new afs_shipment_carries();
                                exists.CLIENT          = postdata.client;
                                exists.SHIPMENT_NUMBER = postdata.shipment_number;
                                exists.ITEM_NO         = item.itemno;
                                exists.CREATED_BY      = postdata.created_by;
                                exists.CREATED_DATE    = DateTime.Now;
                            }

                            exists.POINT_DESC       = item.point_desc;
                            exists.TIME_RANGE       = item.time_range;
                            exists.SALEORDER_NUMBER = item.so_number;
                            exists.REMARK           = item.remark;
                            exists.DRIVER_AMOUNT    = item.driver_amount;
                            exists.STAFF_AMOUNT     = item.staff_amount;
                            exists.UPDATE_BY        = postdata.update_by;
                            exists.UPDATE_DATE      = DateTime.Now;

                            if (newdata)
                            {
                                context.afs_shipment_carries.Add(exists);
                            }
                            else
                            {
                                context.Entry(exists).State = EntityState.Modified;
                            }
                        }
                    }

                    // Save Shipment expense
                    if (postdata.shipment_expense != null)
                    {
                        foreach (var item in postdata.shipment_expense)
                        {
                            newdata = false;
                            afs_shipment_expense exp = new afs_shipment_expense();
                            var exists = context.afs_shipment_expense.Where(w =>
                                                                            w.CLIENT == item.client &&
                                                                            w.SHIPMENT_NUMBER == item.shipment_number &&
                                                                            w.ITEM_NO == item.itemno
                                                                            ).FirstOrDefault();
                            if (exists == null)
                            {
                                newdata                = true;
                                exists                 = new afs_shipment_expense();
                                exists.CLIENT          = postdata.client;
                                exists.SHIPMENT_NUMBER = postdata.shipment_number;
                                exists.ITEM_NO         = item.itemno;
                                exists.EXPENSE_ID      = item.expense_id;
                                exists.CREATED_BY      = postdata.created_by;
                                exists.CREATED_DATE    = DateTime.Now;
                            }

                            exists.REMARK         = item.remark;
                            exists.EXPENSE_AMOUNT = item.expense_amount;
                            exists.UPDATE_BY      = postdata.update_by;
                            exists.UPDATE_DATE    = DateTime.Now;

                            if (newdata)
                            {
                                context.afs_shipment_expense.Add(exists);
                            }
                            else
                            {
                                context.Entry(exists).State = EntityState.Modified;
                            }
                        }
                    }

                    // Commit data
                    context.SaveChanges();

                    //Search shipment
                    ShipmentSearchModel searh  = new ShipmentSearchModel();
                    HttpResponseMessage result = new HttpResponseMessage();
                    searh.ShipmentNo = postdata.shipment_number;
                    result           = PostShipmentSearh(searh);
                    return(result);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.InnerException.Message));
            }
        }