public async Task <int> Count(PlaceFilter filter) { IQueryable <PlaceDAO> Places = DataContext.Place.AsNoTracking(); Places = DynamicFilter(Places, filter); return(await Places.CountAsync()); }
public async Task <ActionResult <bool> > BulkDelete([FromBody] List <long> Ids) { if (!ModelState.IsValid) { throw new BindException(ModelState); } PlaceFilter PlaceFilter = new PlaceFilter(); PlaceFilter = await PlaceService.ToFilter(PlaceFilter); PlaceFilter.Id = new IdFilter { In = Ids }; PlaceFilter.Selects = PlaceSelect.Id; PlaceFilter.Skip = 0; PlaceFilter.Take = int.MaxValue; List <Place> Places = await PlaceService.List(PlaceFilter); Places = await PlaceService.BulkDelete(Places); if (Places.Any(x => !x.IsValidated)) { return(BadRequest(Places.Where(x => !x.IsValidated))); } return(true); }
public async Task <List <Tracking_PlaceDTO> > FilterListPlace([FromBody] Tracking_PlaceFilterDTO Tracking_PlaceFilterDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } PlaceFilter PlaceFilter = new PlaceFilter(); PlaceFilter.Skip = 0; PlaceFilter.Take = 20; PlaceFilter.OrderBy = PlaceOrder.Id; PlaceFilter.OrderType = OrderType.ASC; PlaceFilter.Selects = PlaceSelect.ALL; PlaceFilter.Id = Tracking_PlaceFilterDTO.Id; PlaceFilter.Name = Tracking_PlaceFilterDTO.Name; PlaceFilter.PlaceGroupId = Tracking_PlaceFilterDTO.PlaceGroupId; PlaceFilter.Radius = Tracking_PlaceFilterDTO.Radius; PlaceFilter.Latitude = Tracking_PlaceFilterDTO.Latitude; PlaceFilter.Longtitude = Tracking_PlaceFilterDTO.Longtitude; List <Place> Places = await PlaceService.List(PlaceFilter); List <Tracking_PlaceDTO> Tracking_PlaceDTOs = Places .Select(x => new Tracking_PlaceDTO(x)).ToList(); return(Tracking_PlaceDTOs); }
public async Task <PlaceFilter> ToFilter(PlaceFilter filter) { if (filter.OrFilter == null) { filter.OrFilter = new List <PlaceFilter>(); } if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0) { return(filter); } foreach (var currentFilter in CurrentContext.Filters) { PlaceFilter subFilter = new PlaceFilter(); filter.OrFilter.Add(subFilter); List <FilterPermissionDefinition> FilterPermissionDefinitions = currentFilter.Value; foreach (FilterPermissionDefinition FilterPermissionDefinition in FilterPermissionDefinitions) { if (FilterPermissionDefinition.Name == nameof(subFilter.Id)) { subFilter.Id = FilterBuilder.Merge(subFilter.Id, FilterPermissionDefinition.IdFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.Name)) { subFilter.Name = FilterBuilder.Merge(subFilter.Name, FilterPermissionDefinition.StringFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.PlaceGroupId)) { subFilter.PlaceGroupId = FilterBuilder.Merge(subFilter.PlaceGroupId, FilterPermissionDefinition.IdFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.Radius)) { subFilter.Radius = FilterBuilder.Merge(subFilter.Radius, FilterPermissionDefinition.LongFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.Latitude)) { subFilter.Latitude = FilterBuilder.Merge(subFilter.Latitude, FilterPermissionDefinition.DecimalFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.Longtitude)) { subFilter.Longtitude = FilterBuilder.Merge(subFilter.Longtitude, FilterPermissionDefinition.DecimalFilter); } if (FilterPermissionDefinition.Name == nameof(CurrentContext.UserId) && FilterPermissionDefinition.IdFilter != null) { if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.IS.Id) { } if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.ISNT.Id) { } } } } return(filter); }
public async Task <List <Place> > List(PlaceFilter PlaceFilter) { try { List <Place> Places = await UOW.PlaceRepository.List(PlaceFilter); return(Places); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(PlaceService)); } return(null); }
public async Task <List <Place> > List(PlaceFilter filter) { if (filter == null) { return(new List <Place>()); } IQueryable <PlaceDAO> PlaceDAOs = DataContext.Place.AsNoTracking(); PlaceDAOs = DynamicFilter(PlaceDAOs, filter); PlaceDAOs = DynamicOrder(PlaceDAOs, filter); List <Place> Places = await DynamicSelect(PlaceDAOs, filter); return(Places); }
public async Task <int> Count(PlaceFilter PlaceFilter) { try { int result = await UOW.PlaceRepository.Count(PlaceFilter); return(result); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(PlaceService)); } return(0); }
public async Task <ActionResult <int> > Count([FromBody] Place_PlaceFilterDTO Place_PlaceFilterDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } PlaceFilter PlaceFilter = ConvertFilterDTOToFilterEntity(Place_PlaceFilterDTO); PlaceFilter = await PlaceService.ToFilter(PlaceFilter); int count = await PlaceService.Count(PlaceFilter); return(count); }
public async Task <ActionResult <List <Place_PlaceDTO> > > List([FromBody] Place_PlaceFilterDTO Place_PlaceFilterDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } PlaceFilter PlaceFilter = ConvertFilterDTOToFilterEntity(Place_PlaceFilterDTO); PlaceFilter = await PlaceService.ToFilter(PlaceFilter); List <Place> Places = await PlaceService.List(PlaceFilter); List <Place_PlaceDTO> Place_PlaceDTOs = Places .Select(c => new Place_PlaceDTO(c)).ToList(); return(Place_PlaceDTOs); }
private IQueryable <PlaceDAO> DynamicFilter(IQueryable <PlaceDAO> query, PlaceFilter filter) { if (filter == null) { return(query.Where(q => false)); } query = query.Where(q => !q.DeletedAt.HasValue); if (filter.CreatedAt != null && filter.CreatedAt.HasValue) { query = query.Where(q => q.CreatedAt, filter.CreatedAt); } if (filter.UpdatedAt != null && filter.UpdatedAt.HasValue) { query = query.Where(q => q.UpdatedAt, filter.UpdatedAt); } if (filter.Id != null && filter.Id.HasValue) { query = query.Where(q => q.Id, filter.Id); } if (filter.Name != null && filter.Name.HasValue) { query = query.Where(q => q.Name, filter.Name); } if (filter.PlaceGroupId != null && filter.PlaceGroupId.HasValue) { query = query.Where(q => q.PlaceGroupId.HasValue).Where(q => q.PlaceGroupId.Value, filter.PlaceGroupId); } if (filter.Radius != null && filter.Radius.HasValue) { query = query.Where(q => q.Radius, filter.Radius); } if (filter.Latitude != null && filter.Latitude.HasValue) { query = query.Where(q => q.Latitude, filter.Latitude); } if (filter.Longtitude != null && filter.Longtitude.HasValue) { query = query.Where(q => q.Longtitude, filter.Longtitude); } query = OrFilter(query, filter); return(query); }
public async Task <bool> ValidateId(Place Place) { PlaceFilter PlaceFilter = new PlaceFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = Place.Id }, Selects = PlaceSelect.Id }; int count = await UOW.PlaceRepository.Count(PlaceFilter); if (count == 0) { Place.AddError(nameof(PlaceValidator), nameof(Place.Id), ErrorCode.IdNotExisted); } return(count == 1); }
private PlaceFilter ConvertFilterDTOToFilterEntity(Place_PlaceFilterDTO Place_PlaceFilterDTO) { PlaceFilter PlaceFilter = new PlaceFilter(); PlaceFilter.Selects = PlaceSelect.ALL; PlaceFilter.Skip = Place_PlaceFilterDTO.Skip; PlaceFilter.Take = Place_PlaceFilterDTO.Take; PlaceFilter.OrderBy = Place_PlaceFilterDTO.OrderBy; PlaceFilter.OrderType = Place_PlaceFilterDTO.OrderType; PlaceFilter.Id = Place_PlaceFilterDTO.Id; PlaceFilter.Name = Place_PlaceFilterDTO.Name; PlaceFilter.PlaceGroupId = Place_PlaceFilterDTO.PlaceGroupId; PlaceFilter.Radius = Place_PlaceFilterDTO.Radius; PlaceFilter.Latitude = Place_PlaceFilterDTO.Latitude; PlaceFilter.Longtitude = Place_PlaceFilterDTO.Longtitude; PlaceFilter.CreatedAt = Place_PlaceFilterDTO.CreatedAt; PlaceFilter.UpdatedAt = Place_PlaceFilterDTO.UpdatedAt; return(PlaceFilter); }
private IQueryable <PlaceDAO> OrFilter(IQueryable <PlaceDAO> query, PlaceFilter filter) { if (filter.OrFilter == null || filter.OrFilter.Count == 0) { return(query); } IQueryable <PlaceDAO> initQuery = query.Where(q => false); foreach (PlaceFilter PlaceFilter in filter.OrFilter) { IQueryable <PlaceDAO> queryable = query; if (PlaceFilter.Id != null && PlaceFilter.Id.HasValue) { queryable = queryable.Where(q => q.Id, filter.Id); } if (PlaceFilter.Name != null && PlaceFilter.Name.HasValue) { queryable = queryable.Where(q => q.Name, filter.Name); } if (PlaceFilter.PlaceGroupId != null && PlaceFilter.PlaceGroupId.HasValue) { queryable = queryable.Where(q => q.PlaceGroupId.HasValue).Where(q => q.PlaceGroupId.Value, filter.PlaceGroupId); } if (PlaceFilter.Radius != null && PlaceFilter.Radius.HasValue) { queryable = queryable.Where(q => q.Radius, filter.Radius); } if (PlaceFilter.Latitude != null && PlaceFilter.Latitude.HasValue) { queryable = queryable.Where(q => q.Latitude, filter.Latitude); } if (PlaceFilter.Longtitude != null && PlaceFilter.Longtitude.HasValue) { queryable = queryable.Where(q => q.Longtitude, filter.Longtitude); } initQuery = initQuery.Union(queryable); } return(initQuery); }
private async Task <bool> HasPermission(long Id) { PlaceFilter PlaceFilter = new PlaceFilter(); PlaceFilter = await PlaceService.ToFilter(PlaceFilter); if (Id == 0) { } else { PlaceFilter.Id = new IdFilter { Equal = Id }; int count = await PlaceService.Count(PlaceFilter); if (count == 0) { return(false); } } return(true); }
public async Task <ActionResult> Import(IFormFile file) { if (!ModelState.IsValid) { throw new BindException(ModelState); } AppUserFilter AppUserFilter = new AppUserFilter { Skip = 0, Take = int.MaxValue, Selects = AppUserSelect.ALL }; List <AppUser> AppUsers = await AppUserService.List(AppUserFilter); PlaceFilter PlaceFilter = new PlaceFilter { Skip = 0, Take = int.MaxValue, Selects = PlaceSelect.ALL }; List <Place> Places = await PlaceService.List(PlaceFilter); CheckingStatusFilter PlaceCheckingStatusFilter = new CheckingStatusFilter { Skip = 0, Take = int.MaxValue, Selects = CheckingStatusSelect.ALL }; List <CheckingStatus> PlaceCheckingStatuses = await CheckingStatusService.List(PlaceCheckingStatusFilter); List <PlaceChecking> PlaceCheckings = new List <PlaceChecking>(); using (ExcelPackage excelPackage = new ExcelPackage(file.OpenReadStream())) { ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.FirstOrDefault(); if (worksheet == null) { return(Ok(PlaceCheckings)); } int StartColumn = 1; int StartRow = 1; int IdColumn = 0 + StartColumn; int AppUserIdColumn = 1 + StartColumn; int PlaceIdColumn = 2 + StartColumn; int PlaceCheckingStatusIdColumn = 3 + StartColumn; int CheckInAtColumn = 4 + StartColumn; int CheckOutAtColumn = 5 + StartColumn; for (int i = StartRow; i <= worksheet.Dimension.End.Row; i++) { if (string.IsNullOrEmpty(worksheet.Cells[i + StartRow, StartColumn].Value?.ToString())) { break; } string IdValue = worksheet.Cells[i + StartRow, IdColumn].Value?.ToString(); string AppUserIdValue = worksheet.Cells[i + StartRow, AppUserIdColumn].Value?.ToString(); string PlaceIdValue = worksheet.Cells[i + StartRow, PlaceIdColumn].Value?.ToString(); string PlaceCheckingStatusIdValue = worksheet.Cells[i + StartRow, PlaceCheckingStatusIdColumn].Value?.ToString(); string CheckInAtValue = worksheet.Cells[i + StartRow, CheckInAtColumn].Value?.ToString(); string CheckOutAtValue = worksheet.Cells[i + StartRow, CheckOutAtColumn].Value?.ToString(); PlaceChecking PlaceChecking = new PlaceChecking(); PlaceChecking.CheckInAt = DateTime.TryParse(CheckInAtValue, out DateTime CheckInAt) ? CheckInAt : DateTime.Now; PlaceChecking.CheckOutAt = DateTime.TryParse(CheckOutAtValue, out DateTime CheckOutAt) ? CheckOutAt : DateTime.Now; AppUser AppUser = AppUsers.Where(x => x.Id.ToString() == AppUserIdValue).FirstOrDefault(); PlaceChecking.AppUserId = AppUser == null ? 0 : AppUser.Id; PlaceChecking.AppUser = AppUser; Place Place = Places.Where(x => x.Id.ToString() == PlaceIdValue).FirstOrDefault(); PlaceChecking.PlaceId = Place == null ? 0 : Place.Id; PlaceChecking.Place = Place; CheckingStatus PlaceCheckingStatus = PlaceCheckingStatuses.Where(x => x.Id.ToString() == PlaceCheckingStatusIdValue).FirstOrDefault(); PlaceChecking.PlaceCheckingStatusId = PlaceCheckingStatus == null ? 0 : PlaceCheckingStatus.Id; PlaceChecking.PlaceCheckingStatus = PlaceCheckingStatus; PlaceCheckings.Add(PlaceChecking); } } PlaceCheckings = await PlaceCheckingService.Import(PlaceCheckings); if (PlaceCheckings.All(x => x.IsValidated)) { return(Ok(true)); } else { List <string> Errors = new List <string>(); for (int i = 0; i < PlaceCheckings.Count; i++) { PlaceChecking PlaceChecking = PlaceCheckings[i]; if (!PlaceChecking.IsValidated) { string Error = $"Dòng {i + 2} có lỗi:"; if (PlaceChecking.Errors.ContainsKey(nameof(PlaceChecking.Id))) { Error += PlaceChecking.Errors[nameof(PlaceChecking.Id)]; } if (PlaceChecking.Errors.ContainsKey(nameof(PlaceChecking.AppUserId))) { Error += PlaceChecking.Errors[nameof(PlaceChecking.AppUserId)]; } if (PlaceChecking.Errors.ContainsKey(nameof(PlaceChecking.PlaceId))) { Error += PlaceChecking.Errors[nameof(PlaceChecking.PlaceId)]; } if (PlaceChecking.Errors.ContainsKey(nameof(PlaceChecking.PlaceCheckingStatusId))) { Error += PlaceChecking.Errors[nameof(PlaceChecking.PlaceCheckingStatusId)]; } if (PlaceChecking.Errors.ContainsKey(nameof(PlaceChecking.CheckInAt))) { Error += PlaceChecking.Errors[nameof(PlaceChecking.CheckInAt)]; } if (PlaceChecking.Errors.ContainsKey(nameof(PlaceChecking.CheckOutAt))) { Error += PlaceChecking.Errors[nameof(PlaceChecking.CheckOutAt)]; } Errors.Add(Error); } } return(BadRequest(Errors)); } }
public Task <PlaceLikelihoodBufferResponse> GetCurrentPlaceAsync(PlaceFilter placeFilter) { return(GetCurrentPlace(placeFilter).AsAsync <PlaceLikelihoodBufferResponse>()); }
private IQueryable <PlaceDAO> DynamicOrder(IQueryable <PlaceDAO> query, PlaceFilter filter) { switch (filter.OrderType) { case OrderType.ASC: switch (filter.OrderBy) { case PlaceOrder.Id: query = query.OrderBy(q => q.Id); break; case PlaceOrder.Name: query = query.OrderBy(q => q.Name); break; case PlaceOrder.PlaceGroup: query = query.OrderBy(q => q.PlaceGroupId); break; case PlaceOrder.Radius: query = query.OrderBy(q => q.Radius); break; case PlaceOrder.Latitude: query = query.OrderBy(q => q.Latitude); break; case PlaceOrder.Longtitude: query = query.OrderBy(q => q.Longtitude); break; } break; case OrderType.DESC: switch (filter.OrderBy) { case PlaceOrder.Id: query = query.OrderByDescending(q => q.Id); break; case PlaceOrder.Name: query = query.OrderByDescending(q => q.Name); break; case PlaceOrder.PlaceGroup: query = query.OrderByDescending(q => q.PlaceGroupId); break; case PlaceOrder.Radius: query = query.OrderByDescending(q => q.Radius); break; case PlaceOrder.Latitude: query = query.OrderByDescending(q => q.Latitude); break; case PlaceOrder.Longtitude: query = query.OrderByDescending(q => q.Longtitude); break; } break; } query = query.Skip(filter.Skip).Take(filter.Take); return(query); }
private async Task <List <Place> > DynamicSelect(IQueryable <PlaceDAO> query, PlaceFilter filter) { List <Place> Places = await query.Select(q => new Place() { Id = filter.Selects.Contains(PlaceSelect.Id) ? q.Id : default(long), Name = filter.Selects.Contains(PlaceSelect.Name) ? q.Name : default(string), PlaceGroupId = filter.Selects.Contains(PlaceSelect.PlaceGroup) ? q.PlaceGroupId : default(long?), Radius = filter.Selects.Contains(PlaceSelect.Radius) ? q.Radius : default(long), Latitude = filter.Selects.Contains(PlaceSelect.Latitude) ? q.Latitude : default(decimal), Longtitude = filter.Selects.Contains(PlaceSelect.Longtitude) ? q.Longtitude : default(decimal), PlaceGroup = filter.Selects.Contains(PlaceSelect.PlaceGroup) && q.PlaceGroup != null ? new PlaceGroup { Id = q.PlaceGroup.Id, ParentId = q.PlaceGroup.ParentId, Name = q.PlaceGroup.Name, Code = q.PlaceGroup.Code, } : null, }).ToListAsync(); return(Places); }
protected override void Execute(NativeActivityContext context) { var width = DialogWidth.Get(context); var height = DialogHeight.Get(context); var placeFilter = PlaceFilter.Get(context); var operationCode = OperationCode.Get(context); var place = InvoicePlace.Get(context); var iwb = IWB.Get(context); var mandantId = MandantID.Get(context); using (var viewModel = (AcceptanceViewModel)IoC.Instance.Resolve(typeof(AcceptanceViewModel))) { viewModel.PrintTE = CheckPrintTE(mandantId); viewModel.PlaceFilter = placeFilter; viewModel.OperationCode = operationCode; viewModel.MandantId = mandantId; viewModel.CurrentIWB = iwb; viewModel.IsMigration = IsMigration.Get(context); viewModel.BatchcodeWorkflowCode = BatchcodeWorkflowCode.Get(context); viewModel.SkuChangeMpWorkflowCode = SkuChangeMpWorkflowCode.Get(context); viewModel.PanelCaption = Title; viewModel.IsProductsShown = IsNeedShowProducts.Get(context); viewModel.DisplayFieldsFormat = DisplayFieldsFormat.Get(context); if (place != null) { viewModel.AcceptancePlace = new EntityReference(place.PlaceCode, Place.EntityType, new[] { new EntityReferenceFieldValue("PlaceCode", place.PlaceCode), new EntityReferenceFieldValue("PlaceName", place.PlaceName) }); } ((IModelHandler)viewModel).SetSource(Source.Get(context)); var viewService = IoC.Instance.Resolve <IViewService>(); if (viewService.ShowDialogWindow(viewModel, true, false, width, height, noButtons: true) == true && viewModel.IsAllowAccept == true) { if (viewModel.SelectedItems != null && viewModel.SelectedItems.Any()) { // пометим выбранные записи foreach (var r in viewModel.Source) { r.IsSelected = viewModel.SelectedItems.Contains(r); } } Result.Set(context, viewModel.Source.Cast <IWBPosInput>().ToArray()); var acceptancePlace = GetAcceptancePlace(viewModel); InvoicePlace.Set(context, acceptancePlace); IsNeedShowProducts.Set(context, viewModel.IsProductsShown); DialogResult.Set(context, true); } else { DialogResult.Set(context, false); } PrintTE.Set(context, viewModel.PrintTE); } }
protected override void Execute(NativeActivityContext context) { var width = DialogWidth.Get(context); var height = DialogHeight.Get(context); var placeFilter = PlaceFilter.Get(context); var operationCode = OperationCode.Get(context); var place = InvoicePlace.Get(context); var obj = (IWBPosInputWithPlaceListViewModel)IoC.Instance.Resolve(typeof(IWBPosInputWithPlaceListViewModel)); var mandantId = MandantID.Get(context); obj.PrintTE = CheckPrintTE(mandantId); obj.PlaceFilter = placeFilter; obj.OperationCode = operationCode; obj.MandantId = mandantId; var isMigration = IsMigration.Get(context); obj.IsMigration = isMigration; obj.BatchcodeWorkflowCode = BatchcodeWorkflowCode.Get(context); obj.SkuChangeMpWorkflowCode = SkuChangeMpWorkflowCode.Get(context); var model = obj as ICustomListViewModel <IWBPosInput>; if (model == null) { throw new DeveloperException("ViewModel doesn't implement ICustomListViewModel."); } model.PanelCaption = Title; var source = Source.Get(context).Select(p => new IwbPosInputErrorInfo(p) { IsSelected = false }); model.SetSource(new ObservableCollection <IWBPosInput>(source)); obj.CurrentPlace = place; var viewService = IoC.Instance.Resolve <IViewService>(); if (viewService.ShowDialogWindow(model, true, false, width, height) == true) { var result = model.GetSource() as IEnumerable <IWBPosInput>; if (result == null) { throw new DeveloperException("Source type is not IEnumerable."); } if (obj.SelectedItems != null && obj.SelectedItems.Any()) { // пометим выбранные записи foreach (var r in result) { r.IsSelected = obj.SelectedItems.Contains(r); } } Result.Set(context, result.ToArray()); InvoicePlace.Set(context, obj.SelectedPlace); DialogResult.Set(context, true); } else { DialogResult.Set(context, false); } PrintTE.Set(context, ((IWBPosInputWithPlaceListViewModel)model).PrintTE); var disposable = model as IDisposable; if (disposable != null) { disposable.Dispose(); } }
public async Task <ActionResult> Export([FromBody] PlaceChecking_PlaceCheckingFilterDTO PlaceChecking_PlaceCheckingFilterDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } MemoryStream memoryStream = new MemoryStream(); using (ExcelPackage excel = new ExcelPackage(memoryStream)) { #region PlaceChecking var PlaceCheckingFilter = ConvertFilterDTOToFilterEntity(PlaceChecking_PlaceCheckingFilterDTO); PlaceCheckingFilter.Skip = 0; PlaceCheckingFilter.Take = int.MaxValue; PlaceCheckingFilter = await PlaceCheckingService.ToFilter(PlaceCheckingFilter); List <PlaceChecking> PlaceCheckings = await PlaceCheckingService.List(PlaceCheckingFilter); var PlaceCheckingHeaders = new List <string[]>() { new string[] { "Id", "AppUserId", "PlaceId", "PlaceCheckingStatusId", "CheckInAt", "CheckOutAt", } }; List <object[]> PlaceCheckingData = new List <object[]>(); for (int i = 0; i < PlaceCheckings.Count; i++) { var PlaceChecking = PlaceCheckings[i]; PlaceCheckingData.Add(new Object[] { PlaceChecking.Id, PlaceChecking.AppUserId, PlaceChecking.PlaceId, PlaceChecking.PlaceCheckingStatusId, PlaceChecking.CheckInAt, PlaceChecking.CheckOutAt, }); } excel.GenerateWorksheet("PlaceChecking", PlaceCheckingHeaders, PlaceCheckingData); #endregion #region AppUser var AppUserFilter = new AppUserFilter(); AppUserFilter.Selects = AppUserSelect.ALL; AppUserFilter.OrderBy = AppUserOrder.Id; AppUserFilter.OrderType = OrderType.ASC; AppUserFilter.Skip = 0; AppUserFilter.Take = int.MaxValue; List <AppUser> AppUsers = await AppUserService.List(AppUserFilter); var AppUserHeaders = new List <string[]>() { new string[] { "Id", "Username", "Password", "DisplayName", "Email", "Phone", "Used", } }; List <object[]> AppUserData = new List <object[]>(); for (int i = 0; i < AppUsers.Count; i++) { var AppUser = AppUsers[i]; AppUserData.Add(new Object[] { AppUser.Id, AppUser.Username, AppUser.Password, AppUser.DisplayName, AppUser.Email, AppUser.Phone, }); } excel.GenerateWorksheet("AppUser", AppUserHeaders, AppUserData); #endregion #region Place var PlaceFilter = new PlaceFilter(); PlaceFilter.Selects = PlaceSelect.ALL; PlaceFilter.OrderBy = PlaceOrder.Id; PlaceFilter.OrderType = OrderType.ASC; PlaceFilter.Skip = 0; PlaceFilter.Take = int.MaxValue; List <Place> Places = await PlaceService.List(PlaceFilter); var PlaceHeaders = new List <string[]>() { new string[] { "Id", "Name", "PlaceGroupId", "Radius", "Latitude", "Longtitude", } }; List <object[]> PlaceData = new List <object[]>(); for (int i = 0; i < Places.Count; i++) { var Place = Places[i]; PlaceData.Add(new Object[] { Place.Id, Place.Name, Place.PlaceGroupId, Place.Radius, Place.Latitude, Place.Longtitude, }); } excel.GenerateWorksheet("Place", PlaceHeaders, PlaceData); #endregion #region CheckingStatus var CheckingStatusFilter = new CheckingStatusFilter(); CheckingStatusFilter.Selects = CheckingStatusSelect.ALL; CheckingStatusFilter.OrderBy = CheckingStatusOrder.Id; CheckingStatusFilter.OrderType = OrderType.ASC; CheckingStatusFilter.Skip = 0; CheckingStatusFilter.Take = int.MaxValue; List <CheckingStatus> CheckingStatuses = await CheckingStatusService.List(CheckingStatusFilter); var CheckingStatusHeaders = new List <string[]>() { new string[] { "Id", "Code", "Name", } }; List <object[]> CheckingStatusData = new List <object[]>(); for (int i = 0; i < CheckingStatuses.Count; i++) { var CheckingStatus = CheckingStatuses[i]; CheckingStatusData.Add(new Object[] { CheckingStatus.Id, CheckingStatus.Code, CheckingStatus.Name, }); } excel.GenerateWorksheet("CheckingStatus", CheckingStatusHeaders, CheckingStatusData); #endregion excel.Save(); } return(File(memoryStream.ToArray(), "application/octet-stream", "PlaceChecking.xlsx")); }
public static async Task <PlaceLikelihoodBuffer> GetCurrentPlaceAsync(this IPlaceDetectionApi api, GoogleApiClient client, PlaceFilter filter) { return((await api.GetCurrentPlace(client, filter)).JavaCast <PlaceLikelihoodBuffer> ()); }
public async Task <ActionResult> Import(IFormFile file) { if (!ModelState.IsValid) { throw new BindException(ModelState); } PlaceFilter PlaceFilter = new PlaceFilter { Skip = 0, Take = int.MaxValue, Selects = PlaceSelect.ALL }; List <Place> Places = await PlaceService.List(PlaceFilter); PlaceCheckingFilter PlaceCheckingFilter = new PlaceCheckingFilter { Skip = 0, Take = int.MaxValue, Selects = PlaceCheckingSelect.ALL }; List <PlaceChecking> PlaceCheckings = await PlaceCheckingService.List(PlaceCheckingFilter); AppUserFilter TargetFilter = new AppUserFilter { Skip = 0, Take = int.MaxValue, Selects = AppUserSelect.ALL }; List <AppUser> Targets = await AppUserService.List(TargetFilter); AppUserFilter TrackerFilter = new AppUserFilter { Skip = 0, Take = int.MaxValue, Selects = AppUserSelect.ALL }; List <AppUser> Trackers = await AppUserService.List(TrackerFilter); List <Tracking> Trackings = new List <Tracking>(); using (ExcelPackage excelPackage = new ExcelPackage(file.OpenReadStream())) { ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.FirstOrDefault(); if (worksheet == null) { return(Ok(Trackings)); } int StartColumn = 1; int StartRow = 1; int IdColumn = 0 + StartColumn; int TrackerIdColumn = 1 + StartColumn; int TargetIdColumn = 2 + StartColumn; int PlaceIdColumn = 3 + StartColumn; int PlaceCheckingIdColumn = 4 + StartColumn; int UsedColumn = 8 + StartColumn; for (int i = StartRow; i <= worksheet.Dimension.End.Row; i++) { if (string.IsNullOrEmpty(worksheet.Cells[i + StartRow, StartColumn].Value?.ToString())) { break; } string IdValue = worksheet.Cells[i + StartRow, IdColumn].Value?.ToString(); string TrackerIdValue = worksheet.Cells[i + StartRow, TrackerIdColumn].Value?.ToString(); string TargetIdValue = worksheet.Cells[i + StartRow, TargetIdColumn].Value?.ToString(); string PlaceIdValue = worksheet.Cells[i + StartRow, PlaceIdColumn].Value?.ToString(); string PlaceCheckingIdValue = worksheet.Cells[i + StartRow, PlaceCheckingIdColumn].Value?.ToString(); string UsedValue = worksheet.Cells[i + StartRow, UsedColumn].Value?.ToString(); Tracking Tracking = new Tracking(); Place Place = Places.Where(x => x.Id.ToString() == PlaceIdValue).FirstOrDefault(); Tracking.PlaceId = Place == null ? 0 : Place.Id; Tracking.Place = Place; PlaceChecking PlaceChecking = PlaceCheckings.Where(x => x.Id.ToString() == PlaceCheckingIdValue).FirstOrDefault(); Tracking.PlaceCheckingId = PlaceChecking == null ? 0 : PlaceChecking.Id; Tracking.PlaceChecking = PlaceChecking; AppUser Target = Targets.Where(x => x.Id.ToString() == TargetIdValue).FirstOrDefault(); Tracking.TargetId = Target == null ? 0 : Target.Id; Tracking.Target = Target; AppUser Tracker = Trackers.Where(x => x.Id.ToString() == TrackerIdValue).FirstOrDefault(); Tracking.TrackerId = Tracker == null ? 0 : Tracker.Id; Tracking.Tracker = Tracker; Trackings.Add(Tracking); } } Trackings = await TrackingService.Import(Trackings); if (Trackings.All(x => x.IsValidated)) { return(Ok(true)); } else { List <string> Errors = new List <string>(); for (int i = 0; i < Trackings.Count; i++) { Tracking Tracking = Trackings[i]; if (!Tracking.IsValidated) { string Error = $"Dòng {i + 2} có lỗi:"; if (Tracking.Errors.ContainsKey(nameof(Tracking.Id))) { Error += Tracking.Errors[nameof(Tracking.Id)]; } if (Tracking.Errors.ContainsKey(nameof(Tracking.TrackerId))) { Error += Tracking.Errors[nameof(Tracking.TrackerId)]; } if (Tracking.Errors.ContainsKey(nameof(Tracking.TargetId))) { Error += Tracking.Errors[nameof(Tracking.TargetId)]; } if (Tracking.Errors.ContainsKey(nameof(Tracking.PlaceId))) { Error += Tracking.Errors[nameof(Tracking.PlaceId)]; } if (Tracking.Errors.ContainsKey(nameof(Tracking.PlaceCheckingId))) { Error += Tracking.Errors[nameof(Tracking.PlaceCheckingId)]; } Errors.Add(Error); } } return(BadRequest(Errors)); } }