public async Task <ActionResult <WrapperStaffListVM> > DeleteStaff([FromBody] StaffVM Temp) { WrapperStaffListVM data = await _serviceWrapper.StaffService.Delete(Temp); _utilService.Log("Staff Successfully Deleted"); return(data); }
private async Task <WrapperStaffListVM> SetHistoryOverview(WrapperStaffListVM vm, string factoryId) { var data = new GetDataListHistory(); //Task<WrapperStaffHistory>[] listOftask = new Task<WrapperStaffHistory>[vm.ListOfData.Count]; WrapperStaffHistory[] listOftask = new WrapperStaffHistory[vm.ListOfData.Count]; for (int i = 0; i < vm.ListOfData.Count; i++) { StaffVM temp = vm.ListOfData.ElementAt(i); data.ClientId = temp.Id; data.PageNumber = -1; data.FactoryId = factoryId; data.PageSize = -1; listOftask[i] = await GetStaffHistory(data); // StaffHistory te = GetStaffHistoryOverview(listOftask[i]); int len = listOftask[i].ListOfData.Count - 1; vm.ListOfData.ElementAt(i).PaidAmount = listOftask[i].ListOfData[len].PaidAmount; vm.ListOfData.ElementAt(i).RecievableAmount = listOftask[i].ListOfData[len].RecievableAmount; vm.ListOfData.ElementAt(i).RecievedAmount = listOftask[i].ListOfData[len].RecievedAmount; vm.ListOfData.ElementAt(i).PayableAmount = listOftask[i].ListOfData[len].PayableAmount; } // await Task.WhenAll(listOftask); //for (int i = 0; i < vm.ListOfData.Count; i++) //{ //} return(vm); }
public async Task <WrapperStaffListVM> Delete(StaffVM Temp) { var Task = await _repositoryWrapper.Staff.FindByConditionAsync(x => x.Id == Temp.Id && x.FactoryId == Temp.FactoryId); var datarow = Task.ToList().FirstOrDefault(); if (datarow == null) { return(new WrapperStaffListVM()); } _repositoryWrapper.Staff.Delete(datarow); await _repositoryWrapper.Staff.SaveChangesAsync(); this._utilService.Log("Successful In Deleting Data"); var dataParam = new GetDataListVM() { FactoryId = Temp.FactoryId, PageNumber = 1, PageSize = 10, TotalRows = 0 }; WrapperStaffListVM data = await GetListPaged(dataParam, true); return(data); }
public async Task <WrapperStaffListVM> Update(string id, StaffVM ViewModel) { if (id != ViewModel.Id) { new WrapperStaffListVM(); } Task <IEnumerable <Staff> > itemsDB = _repositoryWrapper.Staff.FindByConditionAsync(x => x.Id == id && x.FactoryId == ViewModel.FactoryId); await Task.WhenAll(itemsDB); var itemUpdated = _utilService.GetMapper().Map <StaffVM, Staff>(ViewModel, itemsDB.Result.ToList().FirstOrDefault()); _repositoryWrapper.Staff.Update(itemUpdated); Task <int> t1 = _repositoryWrapper.Staff.SaveChangesAsync(); await Task.WhenAll(t1); this._utilService.Log("Successful In Updating Data"); var dataParam = new GetDataListVM() { FactoryId = ViewModel.FactoryId, PageNumber = 1, PageSize = 10, TotalRows = 0 }; WrapperStaffListVM data = await GetListPaged(dataParam, true); return(data); }
public async Task <WrapperStaffListVM> GetListPaged(GetDataListVM dataListVM, bool withHistory) { IEnumerable <Staff> ListTask = await _repositoryWrapper.Staff.FindByConditionAsync(x => x.FactoryId == dataListVM.FactoryId); long noOfRecordTask = await _repositoryWrapper.Staff.NumOfRecord(); List <Staff> List = ListTask.ToList().OrderByDescending(x => x.UpdatedDateTime).ToList();//.Skip((dataListVM.PageNumber - 1) * dataListVM.PageSize).Take(dataListVM.PageSize).OrderByDescending(x => x.CreatedDateTime).ToList(); List <StaffVM> outputList = new List <StaffVM>(); outputList = _utilService.GetMapper().Map <List <Staff>, List <StaffVM> >(List); List <UserRole> userRoleListT = await _repositoryWrapper .UserRole .FindAll() .Where(x => x.FactoryId == dataListVM.FactoryId) .Include(x => x.Role) .Include(x => x.UserAuthInfo) .ToListAsync(); for (int i = 0; i < userRoleListT.Count(); i++) { StaffVM staff = outputList.Where(x => x.Id == userRoleListT.ElementAt(i).UserAuthInfo.UserId).FirstOrDefault(); if (staff != null) { staff.Role = userRoleListT.ElementAt(i).Role.Name; staff.UserName = userRoleListT.ElementAt(i).UserAuthInfo.UserName; } } if (!string.IsNullOrEmpty(dataListVM.GlobalFilter) && !string.IsNullOrWhiteSpace(dataListVM.GlobalFilter)) { outputList = outputList.Where(output => output.AlternateCellNo != null ? output.AlternateCellNo.Contains(dataListVM.GlobalFilter, StringComparison.OrdinalIgnoreCase) : false || output.CellNo != null ? output.CellNo.Contains(dataListVM.GlobalFilter, StringComparison.OrdinalIgnoreCase) : false || output.Email != null ? output.Email.Contains(dataListVM.GlobalFilter, StringComparison.OrdinalIgnoreCase) : false || output.Name != null ? output.Name.Contains(dataListVM.GlobalFilter, StringComparison.OrdinalIgnoreCase) : false || output.PermanentAddress != null ? output.PermanentAddress.Contains(dataListVM.GlobalFilter, StringComparison.OrdinalIgnoreCase) : false || output.PresentAddress != null ? output.PresentAddress.Contains(dataListVM.GlobalFilter, StringComparison.OrdinalIgnoreCase) : false).ToList(); } outputList = outputList.Skip((dataListVM.PageNumber - 1) * dataListVM.PageSize).Take(dataListVM.PageSize).ToList(); var data = new WrapperStaffListVM(); data.ListOfData = outputList; data.TotalRecords = noOfRecordTask; this._utilService.Log("Successful In Getting Data"); if (withHistory) { data = await SetHistoryOverview(data, dataListVM.FactoryId); } return(data); }
public async Task <ActionResult <WrapperStaffListVM> > AddToStaff([FromBody] StaffVM VM) { WrapperStaffListVM result = new WrapperStaffListVM(); result = await _serviceWrapper.StaffService.AddToIT_Admin(VM); _utilService.Log("Staff Successfully Added"); return(Ok(result)); }
public async Task <ActionResult <WrapperStaffListVM> > UpdateStaff(string id, [FromBody] StaffVM temp) { WrapperStaffListVM result = new WrapperStaffListVM(); result = await _serviceWrapper.StaffService.Update(id, temp); _utilService.Log("Staff Successfully Updated"); return(Ok(result)); }
public async Task <WrapperStaffListVM> Add(StaffVM ViewModel) { var itemToAdd = _utilService.GetMapper().Map <StaffVM, Staff>(ViewModel); itemToAdd = _repositoryWrapper.Staff.Create(itemToAdd); Task <int> t1 = _repositoryWrapper.Staff.SaveChangesAsync(); if (ViewModel.IsManager) { UserAuthInfo infoToAdd = new UserAuthInfo() { FactoryId = ViewModel.FactoryId, Password = ViewModel.Password, UserId = itemToAdd.Id, UserName = ViewModel.UserName, }; infoToAdd = _repositoryWrapper.UserAuthInfo.Create(infoToAdd); UserRole userRoleToAdd = new UserRole() { FactoryId = ViewModel.FactoryId, RoleId = ViewModel.RoleId, UserId = infoToAdd.Id }; userRoleToAdd = _repositoryWrapper.UserRole.Create(userRoleToAdd); Task <int> t2 = _repositoryWrapper.UserAuthInfo.SaveChangesAsync(); Task <int> t3 = _repositoryWrapper.UserRole.SaveChangesAsync(); await Task.WhenAll(t2, t3); } await Task.WhenAll(t1); this._utilService.Log("Successful In Adding Data"); var dataParam = new GetDataListVM() { FactoryId = itemToAdd.FactoryId, PageNumber = 1, PageSize = 10, TotalRows = 0 }; WrapperStaffListVM data = await GetListPaged(dataParam, true); return(data); }