public ActionResult <IEnumerable <DtoEntry> > SaveEntry(EntryModel entry) { DtoEntry added = new DtoEntry(); if (ModelState.IsValid) { try { added = _entryService.RegistryVehicle(EntryMapper.convertModelToDTO(entry)); } catch (Exception e) { if (e is AppException) { return(UnprocessableEntity(e.Message)); } else { return(BadRequest(e.Message)); } } } return(CreatedAtAction(nameof(GetEntry), new { id = added.Id }, added)); }
public async Task <bool> Save(EntryViewModel entryViewModel) { var serializedItem = JsonConvert.SerializeObject(EntryMapper.Map(entryViewModel, new EntryDTO())); if (entryViewModel.EntryId == 0) { try { await _lock.WaitAsync(); var response = await _client.PostAsync($"{Server}/api/entries", new StringContent(serializedItem, Encoding.UTF8, "application/json")); return(response.IsSuccessStatusCode); } finally { _lock.Release(); } } try { await _lock.WaitAsync(); var response = await _client.PutAsync($"{Server}/api/entries/{entryViewModel.EntryId}", new StringContent(serializedItem, Encoding.UTF8, "application/json")); return(response.IsSuccessStatusCode); } finally { _lock.Release(); } }
public async Task <IList <EntryViewModel> > GetEntries(bool forceRefresh = false) { var uri = $"{Server}/api/entries"; var result = await Get <List <EntryDTO> >(uri, CancellationToken.None); return(result.Select(c => EntryMapper.Map(c, new EntryViewModel(), e => e.Updated = false)).ToList()); }
/// <inheritdoc/> public override async Task <IList <CompressedEntryModel> > ExtractAsync(string sourcePath, string destinationPath, CancellationToken ct) { if (string.IsNullOrWhiteSpace(sourcePath)) { throw new ArgumentNullException(nameof(sourcePath)); } if (string.IsNullOrWhiteSpace(destinationPath)) { throw new ArgumentNullException(nameof(destinationPath)); } if (ct == null) { throw new ArgumentNullException(nameof(ct)); } return(await Task.Run( () => { IList <CompressedEntryModel> entries = new List <CompressedEntryModel>(); // TODO: add options as parameters var options = new ReaderOptions() { LeaveStreamOpen = false, LookForHeader = false }; using (var file = File.OpenRead(sourcePath)) { using (var archive = ArchiveFactory.Open(file, options)) using (var comparer = new GenericNaturalComparer <IArchiveEntry>(e => e.Key)) { var sortedEntries = archive.Entries.Sort(comparer).Take(MaxCompressibleEntries); foreach (var entry in sortedEntries) { ct.ThrowIfCancellationRequested(); if (!entry.IsDirectory) { // TODO: add options as parameters var extractionOptions = new ExtractionOptions() { ExtractFullPath = false, Overwrite = false }; entry.WriteToDirectory(destinationPath, extractionOptions); entries.Add(EntryMapper.Map(entry)); } } } } return entries; }, ct)); }
public EntryViewModel GetEntry(int id) { // var behindicator = repository.Get(x => x.BehIndicatorId == id).FirstOrDefault(); // return BehIndicatorMapper.Map(behindicator); //var entry = _er.Get(x => x.EntryId == id,null,"").FirstOrDefault(); var entry = _unitOfWork.Entryrepository.Get(x => x.EntryId == id, null, "").FirstOrDefault(); return(EntryMapper.Map(entry)); }
public ActionResult <DtoEntry> GetEntry(string id) { var cell = EntryMapper.convertDTOToModel(_entryService.GetEntryById(id)); if (cell == null) { return(NotFound()); } return(Ok(cell)); }
public async Task <ActionResult <EntryDTO> > GetEntry([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entry = await _context.Entries.FindAsync(id); if (entry == null) { return(NotFound()); } return(Ok(EntryMapper.Map(entry, new EntryDTO()))); }
public DtoEntry RegistryVehicle(DtoEntry entry) { var lastEntryByIdVehicle = _entryRepository.List(e => e.IdVehicle == entry.IdVehicle).LastOrDefault(); if (lastEntryByIdVehicle != null) { var departure = _departureService.GetDepartureByEntryId(lastEntryByIdVehicle.Id); if (departure == null) { throw new EntryException("El vehículo que está registrando posee una salida pendiente"); } } if (!_cellService.ExistsQuotaByVehicleType(entry.IdVehicleType)) { throw new CellException("No hay cupos disponibles"); } string lastNumberIdVehicle = _placaService.GetLastNumberOfIdVehicle(entry.IdVehicleType, entry.IdVehicle); bool isParsed = short.TryParse(lastNumberIdVehicle, out short numberResult); if (!isParsed) { throw new EntryException("Hubo un problema al leer la placa del vehículo. Verifique el tipo de vehículo e intente de nuevo"); } if (_placaService.HasPicoPlaca(entry.IdVehicleType, (int)DateTime.Now.DayOfWeek, numberResult)) { throw new EntryException("El vehículo no puede ser registrado, tiene pico y placa."); } if ((entry.IdVehicleType == VehicleTypeEnum.motorcycle) && string.IsNullOrEmpty(entry.CC)) { throw new EntryException("Falta la información del cilindraje de la motocicleta"); } var entryEntity = _entryRepository.Add(EntryMapper.ConvertDTOToEntity(entry)); if (entryEntity == null) { throw new EntryException("Ocurrio un problema al guardar el registro"); } _cellService.DecreaseCell(entryEntity.IdVehicleType, 1); return(EntryMapper.ConvertEntityToDTO(entryEntity)); }
/// <inheritdoc/> protected override async Task <IList <ArchivedEntryModel> > AbstractReadAsync(string path, CancellationToken ct) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException(nameof(path)); } if (ct == null) { throw new ArgumentNullException(nameof(ct)); } var fs = FileSystemStrategy.Create(path); if (fs == null) { throw new UnexpectedNullException("Filesystem could not be created based on the provided path."); } IList <ArchivedEntryModel> entries = new List <ArchivedEntryModel>(); var options = new ReaderOptions() { LeaveStreamOpen = false, LookForHeader = false }; using (var file = fs.File.OpenRead(path)) { using (var archive = ArchiveFactory.Open(file, options)) using (var comparer = new GenericNaturalComparer <IArchiveEntry>(e => e.Key)) { var sortedEntries = archive.Entries.Sort(comparer).Take(MaxArchivedEntries); foreach (var entry in sortedEntries) { ct.ThrowIfCancellationRequested(); entries.Add(EntryMapper.Map(entry)); } } } await Task.CompletedTask; return(entries); }
public async Task <ActionResult <EntryDTO> > PostEntry([FromBody] EntryDTO dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entry = EntryMapper.Map(dto, new Entry()); Console.WriteLine(entry.EntryId); _context.Entries.Add(entry); await _context.SaveChangesAsync(); Console.WriteLine(entry.EntryId); return(CreatedAtAction("GetEntry", new { id = entry.EntryId }, entry)); }
/// <inheritdoc/> protected override async Task <IList <CompressedEntryModel> > AbstractReadAsync(string path, CancellationToken ct) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException(nameof(path)); } if (ct == null) { throw new ArgumentNullException(nameof(ct)); } return(await Task.Run( () => { IList <CompressedEntryModel> entries = new List <CompressedEntryModel>(); // TODO: add options as parameters var options = new ReaderOptions() { LeaveStreamOpen = false, LookForHeader = false }; using (var file = File.OpenRead(path)) { using (var archive = ArchiveFactory.Open(file, options)) using (var comparer = new GenericNaturalComparer <IArchiveEntry>(e => e.Key)) { var sortedEntries = archive.Entries.Sort(comparer).Take(MaxCompressibleEntries); foreach (var entry in sortedEntries) { entries.Add(EntryMapper.Map(entry)); } } } return entries; }, ct)); }
public async Task <IActionResult> PutEntry([FromRoute] int id, [FromBody] EntryDTO dto) { Console.WriteLine("I shouldn't be here!"); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dto.EntryId) { return(BadRequest()); } var entry = EntryMapper.Map(dto, new Entry()); _context.Entry(entry).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EntryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void CreateNewEntry(EntryViewModel entry) { _unitOfWork.Entryrepository.CreateNewEntry(EntryMapper.MapToModel(entry)); _unitOfWork.Save(); //_er.CreateNewEntry(EntryMapper.MapToModel(entry)); }
public async Task <ActionResult <IEnumerable <EntryDTO> > > GetEntries() { var entities = await _context.Entries.ToListAsync(); return(Ok(entities.Select(x => EntryMapper.Map(x, new EntryDTO())))); }
public DtoEntry GetEntryById(string id) { return(EntryMapper.ConvertEntityToDTO(_entryRepository.GetById(id))); }
/// <inheritdoc/> public override async Task <IList <ArchivedEntryModel> > ExtractAsync(string sourcePath, string destinationPath, CancellationToken ct, int level = 0) { Ensure.ArgumentNotNullOrWhiteSpace(sourcePath, nameof(sourcePath)); Ensure.ArgumentNotNullOrWhiteSpace(destinationPath, nameof(destinationPath)); Ensure.ArgumentNotNull(ct, nameof(ct)); if (level > 1) { throw new NotSupportedException("The archive contains too many levels."); } ct.ThrowIfCancellationRequested(); var fs = fileSystemStrategy.Create(sourcePath); if (fs == null) { throw new UnexpectedNullException("Filesystem could not be created based on the provided source path."); } IList <ArchivedEntryModel> entries = new List <ArchivedEntryModel>(); var options = new ReaderOptions() { LeaveStreamOpen = false, LookForHeader = false }; using (var file = fs.File.OpenRead(sourcePath)) { using (var archive = ArchiveFactory.Open(file, options)) using (var comparer = new GenericNaturalComparer <IArchiveEntry>(e => e.Key)) { var sortedEntries = archive.Entries .Where(e => !e.IsDirectory) .Sort(comparer) .Take(MaxArchivedEntries > 0 ? MaxArchivedEntries : int.MaxValue); if (MaxSizeKilobytes > 0 && sortedEntries.Sum(e => e.Size) > MaxSizeKilobytes * 1000) { throw new ArgumentException($"The file size exceeds the limit of {MaxSizeKilobytes} kilobytes."); } foreach (var entry in sortedEntries) { ct.ThrowIfCancellationRequested(); // extract all files to destination path (no sub-directories supported) var filename = fs.Path.GetFileName(entry.Key); if (string.IsNullOrWhiteSpace(filename)) { continue; } using (var ms = new MemoryStream()) { entry.WriteTo(ms); fs.File.WriteAllBytes(fs.Path.Combine(destinationPath, filename), ms.ToArray()); } var mappedEntry = EntryMapper.Map(entry); mappedEntry.Key = filename; entries.Add(mappedEntry); } } } if (entries.Count == 1 && entries[0].Key.EndsWith(".tar")) { return(await ExtractAsync(fs.Path.Combine(destinationPath, entries[0].Key), destinationPath, ct, ++level)); } // Delete tarball after extraction if (level == 1 && sourcePath.EndsWith(".tar")) { fs.File.Delete(sourcePath); } await Task.CompletedTask; return(entries); }
public IEnumerable <DtoEntry> GetEntries() { return(EntryMapper.ConvertEntityToDTO(_entryRepository.List().ToList())); }