public async Task <bool> Delete(PlaceChecking PlaceChecking) { if (await ValidateId(PlaceChecking)) { } return(PlaceChecking.IsValidated); }
public async Task <ActionResult <PlaceChecking_PlaceCheckingDTO> > Create([FromBody] PlaceChecking_PlaceCheckingDTO PlaceChecking_PlaceCheckingDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } if (!await HasPermission(PlaceChecking_PlaceCheckingDTO.Id)) { return(Forbid()); } PlaceChecking PlaceChecking = ConvertDTOToEntity(PlaceChecking_PlaceCheckingDTO); PlaceChecking = await PlaceCheckingService.Create(PlaceChecking); PlaceChecking_PlaceCheckingDTO = new PlaceChecking_PlaceCheckingDTO(PlaceChecking); if (PlaceChecking.IsValidated) { return(PlaceChecking_PlaceCheckingDTO); } else { return(BadRequest(PlaceChecking_PlaceCheckingDTO)); } }
public async Task <PlaceChecking> Get(long Id) { PlaceChecking PlaceChecking = await UOW.PlaceCheckingRepository.Get(Id); if (PlaceChecking == null) { return(null); } return(PlaceChecking); }
public PlaceChecking_PlaceCheckingDTO(PlaceChecking PlaceChecking) { this.Id = PlaceChecking.Id; this.AppUserId = PlaceChecking.AppUserId; this.PlaceId = PlaceChecking.PlaceId; this.PlaceCheckingStatusId = PlaceChecking.PlaceCheckingStatusId; this.CheckInAt = PlaceChecking.CheckInAt; this.CheckOutAt = PlaceChecking.CheckOutAt; this.AppUser = PlaceChecking.AppUser == null ? null : new PlaceChecking_AppUserDTO(PlaceChecking.AppUser); this.Place = PlaceChecking.Place == null ? null : new PlaceChecking_PlaceDTO(PlaceChecking.Place); this.PlaceCheckingStatus = PlaceChecking.PlaceCheckingStatus == null ? null : new PlaceChecking_CheckingStatusDTO(PlaceChecking.PlaceCheckingStatus); this.Errors = PlaceChecking.Errors; }
public async Task <ActionResult <PlaceChecking_PlaceCheckingDTO> > Get([FromBody] PlaceChecking_PlaceCheckingDTO PlaceChecking_PlaceCheckingDTO) { if (!ModelState.IsValid) { throw new BindException(ModelState); } if (!await HasPermission(PlaceChecking_PlaceCheckingDTO.Id)) { return(Forbid()); } PlaceChecking PlaceChecking = await PlaceCheckingService.Get(PlaceChecking_PlaceCheckingDTO.Id); return(new PlaceChecking_PlaceCheckingDTO(PlaceChecking)); }
public Tracking_PlaceCheckingDTO(PlaceChecking PlaceChecking) { this.Id = PlaceChecking.Id; this.AppUserId = PlaceChecking.AppUserId; this.PlaceId = PlaceChecking.PlaceId; this.PlaceCheckingStatusId = PlaceChecking.PlaceCheckingStatusId; this.CheckInAt = PlaceChecking.CheckInAt; this.CheckOutAt = PlaceChecking.CheckOutAt; this.Errors = PlaceChecking.Errors; }
public async Task <PlaceChecking> Get(long Id) { PlaceChecking PlaceChecking = await DataContext.PlaceChecking.AsNoTracking() .Where(x => x.Id == Id) .Select(x => new PlaceChecking() { Id = x.Id, AppUserId = x.AppUserId, PlaceId = x.PlaceId, PlaceCheckingStatusId = x.PlaceCheckingStatusId, CheckInAt = x.CheckInAt, CheckOutAt = x.CheckOutAt, AppUser = x.AppUser == null ? null : new AppUser { Id = x.AppUser.Id, Username = x.AppUser.Username, Password = x.AppUser.Password, DisplayName = x.AppUser.DisplayName, Email = x.AppUser.Email, Phone = x.AppUser.Phone, }, Place = x.Place == null ? null : new Place { Id = x.Place.Id, Name = x.Place.Name, PlaceGroupId = x.Place.PlaceGroupId, Radius = x.Place.Radius, Latitude = x.Place.Latitude, Longtitude = x.Place.Longtitude, }, PlaceCheckingStatus = x.PlaceCheckingStatus == null ? null : new CheckingStatus { Id = x.PlaceCheckingStatus.Id, Code = x.PlaceCheckingStatus.Code, Name = x.PlaceCheckingStatus.Name, }, }).FirstOrDefaultAsync(); if (PlaceChecking == null) { return(null); } return(PlaceChecking); }
public async Task <bool> Create(PlaceChecking PlaceChecking) { PlaceCheckingDAO PlaceCheckingDAO = new PlaceCheckingDAO(); PlaceCheckingDAO.Id = PlaceChecking.Id; PlaceCheckingDAO.AppUserId = PlaceChecking.AppUserId; PlaceCheckingDAO.PlaceId = PlaceChecking.PlaceId; PlaceCheckingDAO.PlaceCheckingStatusId = PlaceChecking.PlaceCheckingStatusId; PlaceCheckingDAO.CheckInAt = PlaceChecking.CheckInAt; PlaceCheckingDAO.CheckOutAt = PlaceChecking.CheckOutAt; DataContext.PlaceChecking.Add(PlaceCheckingDAO); await DataContext.SaveChangesAsync(); PlaceChecking.Id = PlaceCheckingDAO.Id; await SaveReference(PlaceChecking); return(true); }
public async Task <bool> ValidateId(PlaceChecking PlaceChecking) { PlaceCheckingFilter PlaceCheckingFilter = new PlaceCheckingFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = PlaceChecking.Id }, Selects = PlaceCheckingSelect.Id }; int count = await UOW.PlaceCheckingRepository.Count(PlaceCheckingFilter); if (count == 0) { PlaceChecking.AddError(nameof(PlaceCheckingValidator), nameof(PlaceChecking.Id), ErrorCode.IdNotExisted); } return(count == 1); }
public async Task <bool> Update(PlaceChecking PlaceChecking) { PlaceCheckingDAO PlaceCheckingDAO = DataContext.PlaceChecking.Where(x => x.Id == PlaceChecking.Id).FirstOrDefault(); if (PlaceCheckingDAO == null) { return(false); } PlaceCheckingDAO.Id = PlaceChecking.Id; PlaceCheckingDAO.AppUserId = PlaceChecking.AppUserId; PlaceCheckingDAO.PlaceId = PlaceChecking.PlaceId; PlaceCheckingDAO.PlaceCheckingStatusId = PlaceChecking.PlaceCheckingStatusId; PlaceCheckingDAO.CheckInAt = PlaceChecking.CheckInAt; PlaceCheckingDAO.CheckOutAt = PlaceChecking.CheckOutAt; await DataContext.SaveChangesAsync(); await SaveReference(PlaceChecking); return(true); }
public async Task <PlaceChecking> Delete(PlaceChecking PlaceChecking) { if (!await PlaceCheckingValidator.Delete(PlaceChecking)) { return(PlaceChecking); } try { await UOW.PlaceCheckingRepository.Delete(PlaceChecking); await Logging.CreateAuditLog(new { }, PlaceChecking, nameof(PlaceCheckingService)); return(PlaceChecking); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(PlaceCheckingService)); } return(null); }
private PlaceChecking ConvertDTOToEntity(PlaceChecking_PlaceCheckingDTO PlaceChecking_PlaceCheckingDTO) { PlaceChecking PlaceChecking = new PlaceChecking(); PlaceChecking.Id = PlaceChecking_PlaceCheckingDTO.Id; PlaceChecking.AppUserId = PlaceChecking_PlaceCheckingDTO.AppUserId; PlaceChecking.PlaceId = PlaceChecking_PlaceCheckingDTO.PlaceId; PlaceChecking.PlaceCheckingStatusId = PlaceChecking_PlaceCheckingDTO.PlaceCheckingStatusId; PlaceChecking.CheckInAt = PlaceChecking_PlaceCheckingDTO.CheckInAt; PlaceChecking.CheckOutAt = PlaceChecking_PlaceCheckingDTO.CheckOutAt; PlaceChecking.AppUser = PlaceChecking_PlaceCheckingDTO.AppUser == null ? null : new AppUser { Id = PlaceChecking_PlaceCheckingDTO.AppUser.Id, Username = PlaceChecking_PlaceCheckingDTO.AppUser.Username, Password = PlaceChecking_PlaceCheckingDTO.AppUser.Password, DisplayName = PlaceChecking_PlaceCheckingDTO.AppUser.DisplayName, Email = PlaceChecking_PlaceCheckingDTO.AppUser.Email, Phone = PlaceChecking_PlaceCheckingDTO.AppUser.Phone, }; PlaceChecking.Place = PlaceChecking_PlaceCheckingDTO.Place == null ? null : new Place { Id = PlaceChecking_PlaceCheckingDTO.Place.Id, Name = PlaceChecking_PlaceCheckingDTO.Place.Name, PlaceGroupId = PlaceChecking_PlaceCheckingDTO.Place.PlaceGroupId, Radius = PlaceChecking_PlaceCheckingDTO.Place.Radius, Latitude = PlaceChecking_PlaceCheckingDTO.Place.Latitude, Longtitude = PlaceChecking_PlaceCheckingDTO.Place.Longtitude, }; PlaceChecking.PlaceCheckingStatus = PlaceChecking_PlaceCheckingDTO.PlaceCheckingStatus == null ? null : new CheckingStatus { Id = PlaceChecking_PlaceCheckingDTO.PlaceCheckingStatus.Id, Code = PlaceChecking_PlaceCheckingDTO.PlaceCheckingStatus.Code, Name = PlaceChecking_PlaceCheckingDTO.PlaceCheckingStatus.Name, }; PlaceChecking.BaseLanguage = CurrentContext.Language; return(PlaceChecking); }
public async Task <PlaceChecking> Update(PlaceChecking PlaceChecking) { if (!await PlaceCheckingValidator.Update(PlaceChecking)) { return(PlaceChecking); } try { var oldData = await UOW.PlaceCheckingRepository.Get(PlaceChecking.Id); await UOW.PlaceCheckingRepository.Update(PlaceChecking); PlaceChecking = await UOW.PlaceCheckingRepository.Get(PlaceChecking.Id); await Logging.CreateAuditLog(PlaceChecking, oldData, nameof(PlaceCheckingService)); return(PlaceChecking); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(PlaceCheckingService)); } return(null); }
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)); } }
public async Task <bool> Create(PlaceChecking PlaceChecking) { return(PlaceChecking.IsValidated); }
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)); } }
private async Task SaveReference(PlaceChecking PlaceChecking) { }
public async Task <bool> Delete(PlaceChecking PlaceChecking) { await DataContext.PlaceChecking.Where(x => x.Id == PlaceChecking.Id).DeleteFromQueryAsync(); return(true); }