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"); }
private void ConvertToTAbsent(TAbsentViewModel vm, TAbsent entity) { entity.AbsentPeriod = new DateTime(vm.AbsentPeriod.Value.Year, vm.AbsentPeriod.Value.Month, 1); entity.AbsentLocation = vm.AbsentLocation; entity.AbsentSupervisor = vm.AbsentSupervisor; entity.AbsentAdmin = vm.AbsentAdmin; entity.AbsentTotalQty = vm.AbsentTotalQty; entity.AbsentTotalResult = vm.AbsentTotalResult; entity.AbsentTotalBbm = vm.AbsentTotalBbm; entity.EquipId = string.IsNullOrEmpty(vm.EquipId) ? null : _equipTasks.One(vm.EquipId); entity.ProjectId = string.IsNullOrEmpty(vm.ProjectId) ? null : _tasks.One(vm.ProjectId); }
private void CalculateTotalAbsent(string ParentAbsentId, TAbsent absent) { var entitys = this._absentDetTasks.GetListNotDeleted(ParentAbsentId); absent.AbsentTotalQty = entitys.Sum(m => m.AbsentDetQty); absent.AbsentTotalResult = entitys.Sum(m => m.AbsentDetResult); absent.AbsentTotalBbm = entitys.Sum(m => m.AbsentDetBbm); absent.ModifiedDate = DateTime.Now; absent.ModifiedBy = User.Identity.Name; absent.DataStatus = EnumDataStatus.Updated.ToString(); _absentTasks.Update(absent); }
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))); }