public JsonResult SaveEditData(TBL_EXCEPTION_MEAL exceptionMeal, string lstShiftID, string lstExceptionQty, string lstExceptionQtyUsed)
        {
            string flag = "";

            try
            {
                JArray LstShiftID          = JArray.Parse(lstShiftID);
                JArray LstExceptionQty     = JArray.Parse(lstExceptionQty);
                JArray LstExceptionQtyUsed = JArray.Parse(lstExceptionQtyUsed);

                DA_ExceptionMeal.Instance.Update(exceptionMeal);

                // Ghi log
                TBL_EXCEPTION_MEAL oldException_Meal = DA_ExceptionMeal.Instance.GetById(exceptionMeal.ExceptionMealID);
                WriteLog("ExceptionMeal", "Edit", oldException_Meal, exceptionMeal);

                // List Old Exception Meal Shift
                List <TBL_EXCEPTION_MEAL_SHIFT> oldException_Meal_Shift = new List <TBL_EXCEPTION_MEAL_SHIFT>();
                foreach (var item in DA_ExceptionMeal_Shift.Instance.GetAll().Where(x => x.ExceptionMealID == exceptionMeal.ExceptionMealID))
                {
                    // Add vào List Old Exception Meal Shift
                    TBL_EXCEPTION_MEAL_SHIFT Exception_Meal_Shift = DA_ExceptionMeal_Shift.Instance.GetById(item.ExceptionMealShiftID);
                    oldException_Meal_Shift.Add(Exception_Meal_Shift);

                    DA_ExceptionMeal_Shift.Instance.Delete(item);
                }

                // List New Exception Meal Shift
                List <TBL_EXCEPTION_MEAL_SHIFT> newException_Meal_Shift = new List <TBL_EXCEPTION_MEAL_SHIFT>();
                for (int i = 0; i < LstExceptionQty.Count; i++)
                {
                    string Qty     = LstExceptionQty[i].ToString();
                    string QtyUsed = LstExceptionQtyUsed[i].ToString();
                    TBL_EXCEPTION_MEAL_SHIFT MealShift = new TBL_EXCEPTION_MEAL_SHIFT();
                    MealShift.ExceptionMealID  = exceptionMeal.ExceptionMealID;
                    MealShift.ShiftID          = int.Parse(LstShiftID[i].ToString());
                    MealShift.ExceptionQty     = Qty == "" ? 0 : int.Parse(Qty);
                    MealShift.ExceptionQtyUsed = QtyUsed == null ? 0 : int.Parse(QtyUsed);
                    DA_ExceptionMeal_Shift.Instance.Insert(MealShift);

                    // Add vào List New Exception Meal Shift
                    newException_Meal_Shift.Add(MealShift);
                }

                // Ghi log
                WriteLog("ExceptionMealShift", "Edit", oldException_Meal_Shift, newException_Meal_Shift);

                flag = "1";

                return(Json(flag, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                flag = "-1";
                throw;
            }
        }
        public JsonResult SaveData(TBL_EXCEPTION_MEAL exceptionMeal, string lstShiftID, string lstExceptionQty)
        {
            string flag = "";

            try
            {
                JArray LstShiftID      = JArray.Parse(lstShiftID);
                JArray LstExceptionQty = JArray.Parse(lstExceptionQty);

                DA_ExceptionMeal.Instance.Insert(exceptionMeal);
                long ExceptionMealID = DA_ExceptionMeal.Instance.GetAll().OrderByDescending(x => x.ExceptionMealID).FirstOrDefault().ExceptionMealID;

                //Ghi log
                WriteLog("ExceptionMeal", "Create", null, exceptionMeal);

                List <TBL_EXCEPTION_MEAL_SHIFT> lstException_Meal_Shift = new List <TBL_EXCEPTION_MEAL_SHIFT>();
                for (int i = 0; i < LstExceptionQty.Count; i++)
                {
                    string Qty = LstExceptionQty[i].ToString();
                    TBL_EXCEPTION_MEAL_SHIFT MealShift = new TBL_EXCEPTION_MEAL_SHIFT();
                    MealShift.ExceptionMealID  = ExceptionMealID;
                    MealShift.ShiftID          = int.Parse(LstShiftID[i].ToString());
                    MealShift.ExceptionQty     = Qty == "" ? 0 : int.Parse(Qty);
                    MealShift.ExceptionQtyUsed = 0;
                    DA_ExceptionMeal_Shift.Instance.Insert(MealShift);

                    //---
                    lstException_Meal_Shift.Add(MealShift);
                }
                //Ghi log
                WriteLog("ExceptionMealShift", "Create", null, lstException_Meal_Shift);

                flag = "1";

                return(Json(flag, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                flag = "-1";
                throw;
            }
        }
        public JsonResult Delete(long ExceptionMealID)
        {
            string flag = "";

            try
            {
                //Ghi log
                TBL_EXCEPTION_MEAL Exception_Meal = DA_ExceptionMeal.Instance.GetById(ExceptionMealID);
                WriteLog("ExceptionMeal", "Delete", Exception_Meal, null);

                DA_ExceptionMeal.Instance.Delete(ExceptionMealID);


                // List Old Exception Meal Shift
                List <TBL_EXCEPTION_MEAL_SHIFT> oldException_Meal_Shift = new List <TBL_EXCEPTION_MEAL_SHIFT>();
                foreach (var item in DA_ExceptionMeal_Shift.Instance.GetAll().Where(x => x.ExceptionMealID == ExceptionMealID))
                {
                    // Add vào List Old Exception Meal Shift
                    TBL_EXCEPTION_MEAL_SHIFT Exception_Meal_Shift = DA_ExceptionMeal_Shift.Instance.GetById(item.ExceptionMealShiftID);
                    oldException_Meal_Shift.Add(Exception_Meal_Shift);

                    DA_ExceptionMeal_Shift.Instance.Delete(item);
                }

                // Ghi log
                WriteLog("ExceptionMealShift", "Delete", oldException_Meal_Shift, null);

                flag = "1";
                return(Json(flag, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                flag = "-1";
                throw;
            }
        }