public static int AddData(DeliveryHistoryDTO Data)
        {
            using (DBEntities db = new DBEntities())
            {
                //get total day
                var total    = DateTime.Now.Subtract(db.TB_CANDIDATE_SELECTION_HISTORY.FirstOrDefault(d => d.CANDIDATE_ID == Data.CANDIDATE_ID && d.CANDIDATE_STATE == 1).PROCESS_DATE.Value);
                int TotalDay = Convert.ToInt16(DateTime.Now.Subtract(db.TB_CANDIDATE_SELECTION_HISTORY.FirstOrDefault(d => d.CANDIDATE_ID == Data.CANDIDATE_ID && d.CANDIDATE_STATE == 1).PROCESS_DATE.Value).ToString("dddd"));

                //get process date
                var process_Date = db.TB_CANDIDATE_SELECTION_HISTORY.FirstOrDefault(d => d.CANDIDATE_ID == Data.CANDIDATE_ID && d.CANDIDATE_STATE == 1).PROCESS_DATE;

                //data candidate
                var DataCandidate = db.TB_CANDIDATE.FirstOrDefault(c => c.ID == Data.CANDIDATE_ID);

                db.TB_DELIVERY_HISTORY.Add(new TB_DELIVERY_HISTORY
                {
                    DELIVERY_ID        = Data.DELIVERY_ID,
                    CANDIDATE_ID       = Data.CANDIDATE_ID,
                    CANDIDATE_POSITION = Data.CANDIDATE_POSITION,
                    SOURCE             = DataCandidate.SOURCE,
                    CANDIDATE_STATE    = Data.CANDIDATE_STATE,
                    LAST_PIC           = Data.LAST_PIC,
                    PROCESS_DATE       = process_Date,
                    CLIENT_ID          = Data.CLIENT_ID,
                    START_DATE         = DateTime.Now,
                    LAST_UPDATE        = DateTime.Now,
                    TOTA_DAY           = TotalDay,
                    CLIENT_STATE       = Data.CLIENT_STATE,
                    NOTE = Data.NOTE
                });

                return(db.SaveChanges());
            }
        }
        public static int EditData(DeliveryHistoryDTO Data)
        {
            using (DBEntities db = new DBEntities())
            {
                TB_DELIVERY_HISTORY DeliveryHistory = db.TB_DELIVERY_HISTORY.FirstOrDefault(d => d.ID == Data.ID);

                //data PIC
                UserDTO DataPic = (UserDTO)HttpContext.Current.Session["UserLogin"];

                DeliveryHistory.CANDIDATE_POSITION = Data.CANDIDATE_POSITION;
                DeliveryHistory.SOURCE             = Data.SOURCE;
                DeliveryHistory.CANDIDATE_STATE    = Data.CANDIDATE_STATE;
                DeliveryHistory.LAST_PIC           = DataPic.USER_ID;
                DeliveryHistory.PROCESS_DATE       = db.TB_CANDIDATE_SELECTION_HISTORY.FirstOrDefault(d => d.CANDIDATE_ID == Data.CANDIDATE_ID && d.CANDIDATE_STATE == 1).PROCESS_DATE;
                DeliveryHistory.CLIENT_ID          = Data.CLIENT_ID;
                DeliveryHistory.LAST_UPDATE        = DateTime.Now;
                DeliveryHistory.CLIENT_STATE       = Data.CLIENT_STATE;
                DeliveryHistory.NOTE = Data.NOTE;

                return(db.SaveChanges());
            }
        }