예제 #1
0
        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);
        }
예제 #2
0
 public void Load(IEnumerable <T> data)
 {
     foreach (var entity in data)
     {
         _repo.Add(entity);
     }
 }
예제 #3
0
        public void Exec(CreatePersonRequest request)
        {
            var e = request.ToEntity();

            e.Home = _homes.ById(request.Home);
            _persons.Add(e);
            _db.SaveChanges();
        }
예제 #4
0
        public static void AddBatch <T>(this IWriteRepository <T> repository, IEnumerable <T> items)
        {
            foreach (var item in items)
            {
                repository.Add(item);
            }

            repository.Save();
        }
예제 #5
0
        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));
        }
예제 #6
0
파일: Program.cs 프로젝트: hikurangi/study
        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();
        }
예제 #7
0
        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();
        }
예제 #8
0
 public void AddProduct(Product product)
 {
     try
     {
         _productWriteRepository.Add(product);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
예제 #9
0
 public void AddUser(User user)
 {
     try
     {
         _userWriteRepository.Add(user);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
예제 #10
0
        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
                });
            }
        }
예제 #11
0
        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)));
        }
예제 #12
0
        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();
        }
예제 #14
0
        public IActionResult PostService([FromBody] Service service)
        {
            _serviceWriteRepository.Add(service);

            return(Ok(service));
        }
예제 #15
0
        public IActionResult PostServiceOrder([FromBody] ServiceOrder serviceOrder)
        {
            _serviceOrderWriteRepository.Add(serviceOrder);

            return(Ok(serviceOrder));
        }
 public void Add(Note note)
 {
     _notesRepository.Add(note);
     _unitOfWork.Save();
 }
예제 #17
0
 public IActionResult PostVehicle([FromBody] Vehicle Vehicle)
 {
     _VehicleWriteRepository.Add(Vehicle);
     return(Ok(Vehicle));
 }
예제 #18
0
        public IActionResult PostOwner([FromBody] Owner owner)
        {
            _ownerWriteRepository.Add(owner);

            return(Ok(owner));
        }
예제 #19
0
 public void Add(TEntity entity) => _writeRepo.Add(entity);
예제 #20
0
 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));
 }
예제 #22
0
 public void Add(TEntity item)
 {
     writeRepository.Add(item);
 }