예제 #1
0
        public ActionResult SaveAbsent(DateTime?workDate, int rowNum, FormCollection formCollection)
        {
            IList <TAbsent> delAbsents = _tAbsentRepository.GetAbsent(workDate);

            for (int i = 0; i < delAbsents.Count; i++)
            {
                TAbsent tAbsentToDelete = _tAbsentRepository.Get(delAbsents[i].Id);

                if (tAbsentToDelete != null)
                {
                    _tAbsentRepository.Delete(tAbsentToDelete);
                }

                try
                {
                    _tAbsentRepository.DbContext.CommitChanges();
                }
                catch (Exception e)
                {
                    _tAbsentRepository.DbContext.RollbackTransaction();
                }
            }
            for (int i = 0; i < rowNum; i++)
            {
                TAbsent tAbsent = new TAbsent();
                if (workDate.HasValue)
                {
                    tAbsent.AbsentDate = workDate.Value;
                }
                tAbsent.SetAssignedIdTo(Guid.NewGuid().ToString());
                tAbsent.EmployeeId  = _mEmployeeRepository.Get(formCollection["id" + i]);
                tAbsent.Status      = formCollection["selectstatus" + i];
                tAbsent.StartTime   = formCollection["starttime" + i] != "" ? DateTime.Parse(formCollection["starttime" + i]) : (DateTime?)null;
                tAbsent.EndTime     = formCollection["endtime" + i] != "" ? DateTime.Parse(formCollection["endtime" + i]) : (DateTime?)null;
                tAbsent.AbsentDesc  = formCollection["desc" + i];
                tAbsent.CreatedDate = DateTime.Now;
                tAbsent.CreatedBy   = User.Identity.Name;
                tAbsent.DataStatus  = EnumDataStatus.New.ToString();

                _tAbsentRepository.Save(tAbsent);

                try
                {
                    _tAbsentRepository.DbContext.CommitChanges();
                }
                catch (Exception e)
                {
                    _tAbsentRepository.DbContext.RollbackTransaction();

                    return(Content(e.GetBaseException().Message));
                }
            }


            return(RedirectToAction("Absent"));//Content("success");
        }
        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)));
        }