private TModel SimpleCreate(TCreateModel createModel) { var model = _mapper.Map <TModel>(createModel); var entity = _mapper.Map <TEntity>(model); var newEntity = _writeRepository.Add(entity); _writeRepository.SaveChanges(); var newModel = _mapper.Map <TModel>(newEntity); return(newModel); }
public void Load(IEnumerable <T> data) { foreach (var entity in data) { _repo.Add(entity); } }
public void Exec(CreatePersonRequest request) { var e = request.ToEntity(); e.Home = _homes.ById(request.Home); _persons.Add(e); _db.SaveChanges(); }
public static void AddBatch <T>(this IWriteRepository <T> repository, IEnumerable <T> items) { foreach (var item in items) { repository.Add(item); } repository.Save(); }
public ActionResult <TDto> Post([FromBody] TDto record) { _logger.LogInformation("Post log"); var entity = _mapper.Map <T>(record); entity.Id = Guid.NewGuid(); _writeRepository.Add(entity); return(CreatedAtAction("Get", new { id = entity.Id }, entity)); }
private static void AddManagers(IWriteRepository <Manager> managerRepository) { var carl = new Manager { FirstName = "Carl" }; var carlCopy = carl.Copy(); if (carlCopy is not null) // C# 9.0 "not" keyword { carlCopy.FirstName += "_Copy"; managerRepository.Add(carlCopy); } managerRepository.Add(carl); managerRepository.Add(new Manager { FirstName = "Lenny" }); managerRepository.Save(); }
public async Task Handle(RegisterForEventCommand command) { var @event = await _writeRepository.GetByIdAsync <Event>(command.EventId); var attendee = @event.Register(command.FirstName, command.LastName); _writeRepository.Add(attendee); await _writeRepository.Commit(); }
public void AddProduct(Product product) { try { _productWriteRepository.Add(product); } catch (Exception ex) { throw; } }
public void AddUser(User user) { try { _userWriteRepository.Add(user); } catch (Exception ex) { throw; } }
public async Task <WriteRequestResult> Add(LocationDetailsDto locationDetails) { try { var locationDetailsModel = _mapper.Map <LocationDetailsModel>(locationDetails); var gameIds = locationDetails.GameOverviewList.Keys.ToList(); locationDetailsModel.GameOverviewList = await CreateValidGamesList(gameIds.ConvertAll(Guid.Parse)); var locationOverviewModel = _mapper.Map <LocationOverviewModel>(locationDetails); var locationExists = await GetLocationIdOrDefault(locationDetailsModel); if (locationExists != default(Guid)) { return(new WriteRequestResult { ItemId = locationExists, Status = WriteRequestStatus.Duplicate }); } var locationId = Guid.NewGuid(); locationDetailsModel.Id = locationId; locationOverviewModel.Id = locationId; // todo: how to undo a write if another fails -> https://stackoverflow.com/questions/51703022/rollback-with-dynamodb var locationDetailsTask = _locationDetailsRepository.Add(locationDetailsModel); var locationOverviewTask = _locationOverviewRepository.Add(locationOverviewModel); await Task.WhenAll(locationDetailsTask, locationOverviewTask); return(new WriteRequestResult { ItemId = null, Status = WriteRequestStatus.Success }); } catch (ValueNotFoundInDatabaseException ex) { // todo: do something when this is found. expectation is that a user will have selected values retrived from the DB only return(new WriteRequestResult { ItemId = null, Status = WriteRequestStatus.Failed }); } catch (Exception ex) { // todo: revise this to look for specific error return(new WriteRequestResult { ItemId = null, Status = WriteRequestStatus.Failed }); } }
public Task <Notas02Notification> Handle(RegistrarClienteCommand request, CancellationToken cancellationToken) { var entity = new Models.Cliente(Guid.Empty, request.Nome); var validator = new RegistrarClienteValidator(); ValidateCliente(ref entity, validator); var result = validator.Validate(new Models.Cliente(Guid.Empty, request.Nome)); if (result.IsValid) { _writeRepository.Add(new Models.Cliente(Guid.Empty, request.Nome)); return(Task.FromResult((Notas02Notification) new Notas02SuccessNotification())); } var results = new Dictionary <string, string>(); foreach (var err in result.Errors) { results.Add(err.PropertyName, err.ErrorMessage); } return(Task.FromResult((Notas02Notification) new Notas02ErrorNotification(results))); }
public Task Handle(TrainerRegisteredEvent notification, CancellationToken cancellationToken) { var trainer = this.trainersReadRepository.GetById(notification.Id); var random = new Random(DateTime.Now.Millisecond); var pokemons = this.definitionsReadRepository.GetAll(); Enumerable.Range(1, RandomPokemonsOnRegister) .Select(_ => random.Next(0, pokemons.Count())) .Select(randomIndex => pokemons.ElementAt(randomIndex)) .Select(definition => new Pokemon(trainer, definition)) .ToList() .ForEach(p => pokemonWriteRepository.Add(p)); pokemonWriteRepository.Save(); return(Task.CompletedTask); }
public void Execute(CreateTaskCommand command) { if (command == null) { throw new ArgumentNullException("command"); } if (string.IsNullOrEmpty(command.Title)) { throw new ArgumentException("Title is not specified", "command"); } var task = new Task(); task.Title = command.Title; task.UserName = command.UserName; task.IsCompleted = command.IsCompleted; task.CreatedDate = command.CreatedOn; task.LastUpdatedDate = command.UpdatedOn; writeRepository.Add(task); writeRepository.Save(); }
public IActionResult PostService([FromBody] Service service) { _serviceWriteRepository.Add(service); return(Ok(service)); }
public IActionResult PostServiceOrder([FromBody] ServiceOrder serviceOrder) { _serviceOrderWriteRepository.Add(serviceOrder); return(Ok(serviceOrder)); }
public void Add(Note note) { _notesRepository.Add(note); _unitOfWork.Save(); }
public IActionResult PostVehicle([FromBody] Vehicle Vehicle) { _VehicleWriteRepository.Add(Vehicle); return(Ok(Vehicle)); }
public IActionResult PostOwner([FromBody] Owner owner) { _ownerWriteRepository.Add(owner); return(Ok(owner)); }
public void Add(TEntity entity) => _writeRepo.Add(entity);
public static void Add <TEntity>(this TEntity entity, IWriteRepository <TEntity> repo) where TEntity : IEntity => repo.Add(entity);
/// <inheritdoc /> public TEntity Add(TEntity entity) { return(_writeRepo.Add(entity)); }
public void Add(TEntity item) { writeRepository.Add(item); }