using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TZONE.Model;

namespace TZONE.DataAccess
{
    public class data_Facade : DataAccessFacadeBase
    {

        public tempdata GetModel(string imei)
        {
            //var q = (from l in DataContext.Product
            //        where l.IMEI==imei
            //        select l).First();
            //var q2 = from l2 in DataContext.Type
            //        where l2.TypeID == q.TypeID
            //        select l2;
            //return q2.Select(
            //    a => new tempdata
            //    {
            //        PID = 0, //q.PID,
            //        imei = q.IMEI,
            //        product_model =a.TypeName,
            //        type_id = a.TypeID
            //    }).SingleOrDefault();

            return new tempdata() 
            {
                PID = 0,
                imei = imei,
                product_model = "AVL301",
                type_id = 1
            };
        }

        public void insert_data(normal model)
        {
            DataContext.TraceData.InsertOnSubmit(new TraceData() {
                IMEI = model.IMEI
                , TypeID = model.TypeID
                , AlarmID = model.Alram
                , GStatus = model.GPRMCState
                , Lat = model.Lat
                , NS = model.NS
                , Lng = model.Lng
                , WE = model.WE
                , Speed = model.Speed
                , Direction = model.Direction
                , PDOP = model.PDOP
                , HDOP = model.HDOP
                , VDOP = model.VDOP
                , VCS = model.VCS
                , VBV = model.VBV
                , VCV = model.VCV
                , ADA = model.ADA
                , ADB = model.ADB
                , LACCI = model.LACCI
                , Temperature = model.Temperature
                , Mileage = model.Mileage
                , IO = model.Status
                , RFID = model.RFID
                , Serial = model.Serial
                , TrackerTime = model.TrackerTime
                , ServerTime = model.ServerTime
                , RTC = model.RTC
                , Address = model.Address
                , C = model.C
                ,isdelete = 0
                ,TagIDList = ""
            });
            DataContext.Original.InsertOnSubmit(new Original() {
                IMEI = model.IMEI
                ,TypeID = model.TypeID
                ,AlarmID = model.Alram
                ,TrackerTime = model.TrackerTime
                ,ServerTime = model.ServerTime
                ,RTC = model.RTC
                ,Length = model.Length
                ,Message = model.Message
                ,C = model.C
                ,isdelete = 0
            });
            DataContext.SubmitChanges();
        }

        
    }
}
