public IActionResult Create(History history) { history.Id = 0; _repository.Create(history); Pet addPetHistory = _petRepository.GetPetById(history.PetId); addPetHistory.Histories.Add(history); return(RedirectToAction("Detail", "Pet", _petRepository.GetPetById(history.PetId))); }
public void CreateHistory(SiteBL site) { var history = new HistoryBL { Date = DateTime.Now, MaxResponseTime = site.MaxResponseTime, MinResponseTime = site.MinResponseTime, SiteId = site.Id, SiteURL = site.Url }; var historyToCreate = _mapper.Map <History>(history); _historyRepository.Create(historyToCreate); }
public async Task <HistoryViewDTO> Create(History history) { var validationResult = _historyValidator.Validate(history); if (!validationResult.IsValid) { throw new Exception(validationResult.ToString()); } else { var createResult = await _historyRepository.Create(history); var mapperResult = _mapper.Map <History, HistoryViewDTO>(createResult); return(mapperResult); } }
public History Pay(string id) { ExternalCart cartToPay = Get(id); if (cartToPay.Products.Count == 0) { return(null); } History history = new History(cartToPay); foreach (var product in cartToPay.Products) { RemoveProduct(id, product.Id); } return(_historyRepository.Create(history)); }
public void CreateResponseHistory(string timageId, TinyResponse responseItem) { var newItem = new TinyPNGResponseHistory { OccuredAt = DateTime.UtcNow, IsOptimized = responseItem.Output.IsOptimized, ImageId = timageId, Error = responseItem.Output.Error, Ratio = responseItem.Output.Ratio, OptimizedSize = responseItem.Output.Size }; if (responseItem.Input != null) { newItem.OriginSize = responseItem.Input.Size; newItem.Error = string.Empty; } _historyRepository.Create(newItem); }
public IActionResult CreateHistory([FromBody] HistoryCreateRequest req) { HistoryResponse resp = _historyRepository.Create(req); return(CreatedAtAction("GetHistoryById", new { historyId = resp.Id }, resp)); }
public virtual void ApplyMigrations(string targetMigration = null) { var connection = _connection.DbConnection; _logger.Value.LogVerbose(Strings.UsingConnection(connection.Database, connection.DataSource)); var migrations = _migrationAssembly.Migrations; var appliedMigrationEntries = _historyRepository.GetAppliedMigrations(); var appliedMigrations = new List <Migration>(); var unappliedMigrations = new List <Migration>(); foreach (var migraion in migrations) { if (appliedMigrationEntries.Any( e => string.Equals(e.MigrationId, migraion.Id, StringComparison.OrdinalIgnoreCase))) { appliedMigrations.Add(migraion); } else { unappliedMigrations.Add(migraion); } } IEnumerable <Migration> migrationsToApply; IEnumerable <Migration> migrationsToRevert; if (string.IsNullOrEmpty(targetMigration)) { migrationsToApply = unappliedMigrations; migrationsToRevert = Enumerable.Empty <Migration>(); } else if (targetMigration == InitialDatabase) { migrationsToApply = Enumerable.Empty <Migration>(); migrationsToRevert = appliedMigrations; } else { targetMigration = _idGenerator.ResolveId(targetMigration, migrations); migrationsToApply = unappliedMigrations .Where(m => string.Compare(m.Id, targetMigration, StringComparison.OrdinalIgnoreCase) <= 0); migrationsToRevert = appliedMigrations .Where(m => string.Compare(m.Id, targetMigration, StringComparison.OrdinalIgnoreCase) > 0) .OrderByDescending(m => m.Id); } bool first; var checkFirst = true; foreach (var migration in migrationsToApply) { var batches = ApplyMigration(migration).ToList(); first = false; if (checkFirst) { first = migration == migrations[0]; if (first && !_historyRepository.Exists()) { // TODO: Consider removing check above and always using "if not exists" batches.Insert(0, new SqlBatch(_historyRepository.Create(ifNotExists: false))); } checkFirst = false; } _logger.Value.LogInformation(Strings.ApplyingMigration(migration.Id)); Execute(batches, first); } foreach (var migration in migrationsToRevert) { _logger.Value.LogInformation(Strings.RevertingMigration(migration.Id)); Execute(RevertMigration(migration)); } }