//[AcceptVerbs(HttpVerbs.Post)]
        //public ActionResult TAbsentDets_Create([DataSourceRequest] DataSourceRequest request, TAbsentDetViewModel vm, string ParentAbsentId)
        //{
        //    if (vm != null && ModelState.IsValid)
        //    {
        //        TAbsentDet entity = new TAbsentDet();
        //        entity.SetAssignedIdTo(Guid.NewGuid().ToString());

        //        ConvertToTAbsentDet(vm, entity,ParentAbsentId);

        //        entity.CreatedDate = DateTime.Now;
        //        entity.CreatedBy = User.Identity.Name;
        //        entity.DataStatus = "New";

        //        _absentDetTasks.Insert(entity);
        //    }

        //    return Json(new[] { vm }.ToDataSourceResult(request, ModelState));
        //}

        private void ConvertToTAbsentDet(TAbsentDetViewModel vm, TAbsentDet entity, string ParentAbsentId)
        {
            //date is read only
            //entity.AbsentDetDate = vm.AbsentDetDate;
            entity.AbsentDetStart    = vm.AbsentDetStart;
            entity.AbsentDetEnd      = vm.AbsentDetEnd;
            entity.AbsentDetQty      = vm.AbsentDetEnd - vm.AbsentDetStart;
            entity.AbsentDetBlock    = vm.AbsentDetBlock;
            entity.AbsentDetResult   = vm.AbsentDetResult;
            entity.AbsentDetBbm      = vm.AbsentDetBbm;
            entity.AbsentDetDesc     = vm.AbsentDetDesc;
            entity.AbsentId          = string.IsNullOrEmpty(ParentAbsentId) ? null : _absentTasks.One(ParentAbsentId);
            entity.AbsentDetOperator = string.IsNullOrEmpty(vm.AbsentDetOperator) ? null : _employeeTasks.One(vm.AbsentDetOperator);
            entity.AbsentDetSinso    = string.IsNullOrEmpty(vm.AbsentDetSinso) ? null : _employeeTasks.One(vm.AbsentDetSinso);
            entity.WorkId            = string.IsNullOrEmpty(vm.WorkId) ? null : _TWorkTasks.One(vm.WorkId);
        }
        public ActionResult TAbsents_Create([DataSourceRequest] DataSourceRequest request, TAbsentViewModel vm)
        {
            if (vm != null && ModelState.IsValid)
            {
                TAbsent entity = new TAbsent();
                entity.SetAssignedIdTo(Guid.NewGuid().ToString());

                ConvertToTAbsent(vm, entity);

                entity.CreatedDate = DateTime.Now;
                entity.CreatedBy   = User.Identity.Name;
                entity.DataStatus  = "New";

                _absentTasks.Insert(entity);

                int        totalDays = entity.AbsentPeriod.Value.AddMonths(1).AddDays(-1).Day;
                DateTime   beginDate = entity.AbsentPeriod.Value;
                TAbsentDet det;
                for (int i = 0; i < totalDays; i++)
                {
                    det = new TAbsentDet();
                    det.SetAssignedIdTo(Guid.NewGuid().ToString());

                    det.AbsentDetDate = beginDate.AddDays(i);
                    det.AbsentId      = entity;

                    det.CreatedDate = DateTime.Now;
                    det.CreatedBy   = User.Identity.Name;
                    det.DataStatus  = "New";

                    _absentDetTasks.Insert(det);
                }
            }

            return(Json(new[] { vm }.ToDataSourceResult(request, ModelState)));
        }