public void AddSaga(Guid id, Guid classId) { if (metadataRecords.ContainsKey(id)) { throw new ArgumentException($"Saga with ID {id} already has metadata added"); } var metadataRecord = metadataRecords[id] = new SagaMetadataRecord(id, classId); crudRepository.Add(metadataRecord); }
public async Task SetEventSourceCheckpointAsync(string eventSourceName, string opaqueCheckpoint) { EventSourceState eventSourceState = await crudRepository.FindAsync <EventSourceState>(eventSourceName); if (eventSourceState == null) { eventSourceState = new EventSourceState(eventSourceName); crudRepository.Add(eventSourceState); } eventSourceState.EventEnqueueCheckpoint = opaqueCheckpoint; }
public void Setup(ICrudRepository <PostStg, string> repo) { repo.Add(new PostStg() { Content = "This value is seeded Into Database.", Title = "DesiredTitle", Id = "A" }); repo.Add(new PostStg() { Content = "This value is seeded Into Database.", Title = "NormalTitle", Id = "B" }); }
public static void Add <TEntity, TId>(this ICrudRepository <TEntity, TId> repository, IEnumerable <TEntity> entities) where TEntity : IEntity <TId> { foreach (var entity in entities) { repository.Add(entity); } }
public virtual IHttpActionResult Create([CanBeNull] TEntity entity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (entity == null) { return(BadRequest("Missing request body.")); } TEntity storedEntity; try { storedEntity = Repository.Add(entity); } catch (KeyNotFoundException ex) { return(BadRequest(ex.Message)); } catch (DataException ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.GetInnerMost().Message)); } return(Created( location: new Uri(Request.RequestUri.EnsureTrailingSlash(), storedEntity.Id.ToString()), content: storedEntity)); }
public void AddDeleteTest() { int countOld = repository.Count; var first = repository.GetAll().FirstOrDefault(); int typeId = first == null ? 1 : first.TypeId; int ownerId = first == null ? 1 : first.Id; toAdd.TypeId = typeId; toAdd.OwnerId = ownerId; using (var transaction = new TransactionScope()) { repository.Add(toAdd); int countAfterAdding = repository.Count; Assert.IsTrue(countAfterAdding == countOld + 1); int lastId = repository.GetAll().Max(x => x.Id); repository.Delete(lastId); int countAfterDeleting = repository.Count; Assert.IsTrue(countAfterDeleting == countOld); transaction.Complete(); } }
public async Task <IActionResult> LikeUser(int id, int recipientId) { if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var like = await _repo.GetLike(id, recipientId); if (like != null) { return(BadRequest("You already liked this user")); } if (await _repo.GetUser(recipientId) == null) { return(NotFound()); } like = new Like { LikerId = id, LikeeId = recipientId }; _repo.Add <Like>(like); if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to like user")); }
public async Task <IActionResult> CreateMessage(int userId, MessageForCreationDto messageForCreationDto) { var sender = await _repo.GetUser(userId); if (sender.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } messageForCreationDto.SenderId = userId; var recipient = await _repo.GetUser(messageForCreationDto.RecipientId); if (recipient == null) { return(BadRequest("Could not find user")); } var message = _mapper.Map <Message>(messageForCreationDto); _repo.Add(message); if (await _repo.SaveAll()) { var messageToReturn = _mapper.Map <MessageToReturnDto>(message); return(CreatedAtRoute("GetMessage", new { id = message.Id }, messageToReturn)); } throw new Exception("Creating the message failed on save"); }
public async Task <IActionResult> Post([FromBody] AddBookModel model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var book = new Book { Name = model.Name, AuthorName = model.AuthorName, Edition = model.Edition, PublicationDate = model.PublicationDate, ISDN = model.ISDN, Category = _repository.GetCategoryWithBooks(model.CategoryId) }; _repository.Add(book); if (await _repository.SaveAllAsync()) { var newUri = Url.Link("BookGet", new { id = book.Id }); return(Created(newUri, book)); } } catch (Exception ex) { Console.Write(ex.Message); } return(BadRequest("Could not post Book")); }
public void Setup(ICrudRepository <Post, long> postsRepository) { postsRepository.Add(new Post { Id = 0, Content = "Welcome to posts blog! This is full of posts! Posts everywhere!", Title = "Welcome" }); var randomContent = "Warning: The Samsung Galaxy S III (International) is no longer maintained. A build guide is available for developers that would like to make private builds, or even restart official support."; postsRepository.Add(new Post { Id = 1, Content = randomContent, Title = _titleSuggestionService.SuggestTitleFor(randomContent) }); }
public void index_get_all() { var controller = new SystemController(_repository); _repository.Add(new Domain.Entities.System() { SystemId = 1, Name = "App 1" }); _repository.Add(new Domain.Entities.System() { SystemId = 2, Name = "App 2" }); var result = controller.Index(); result.Should().BeViewResult().ModelAs <IEnumerable <Domain.Entities.System> >().Should().HaveCount(2); }
public IActionResult Create([FromBody] TaskViewModel model) { var t = new DI.Core.Entities.Task(); t.Name = model.Name; crudRepository.Add(t); return(Ok(t)); }
public IActionResult Post(CrudModels entity) { if (entity == null) { return(BadRequest("The record isn't found!")); } _crudRepository.Add(entity); return(CreatedAtRoute("Get", new { id = entity.ID }, entity)); }
public void index_get_system_methods() { var systemApp1 = new Domain.Entities.System() { SystemId = 1, Name = "App 1" }; var systemApp2 = new Domain.Entities.System() { SystemId = 2, Name = "App 2" }; _systemRepository.Add(systemApp1); _systemRepository.Add(systemApp2); var controller = new MethodController(_repository, _systemRepository); _repository.Add(new Method() { MethodId = 1, Name = "MethodOneInApp1", SystemId = 1 }); _repository.Add(new Method() { MethodId = 2, Name = "MethodOne", SystemId = 2 }); _repository.Add(new Method() { MethodId = 3, Name = "MethodTwo", SystemId = 2 }); _repository.Add(new Method() { MethodId = 4, Name = "MethodThree", SystemId = 2 }); var result = controller.Index(systemApp2.SystemId); result.Should().BeViewResult().ModelAs <IEnumerable <Method> >().Should().HaveCount(3); result.Should() .BeViewResult() .ModelAs <IEnumerable <Method> >() .First(p => p.MethodId == 3) .Name.Should() .Be("MethodTwo"); }
public IActionResult Post([FromBody] Person person) { if (person == null) { BadRequest(); } _repository.Add(person); return(new NoContentResult()); }
public void MainUserAdd(IServiceProvider service) { var user = new User { LastName = "Ajayi", FirstName = "Dotun", Email = "*****@*****.**" }; crudRepository.Add(user); }
public void Add(Image obj) { try { crudRepository.Add(obj); } catch (Exception) { throw; } }
public void Add(ApplicationRole obj) { try { crudRepository.Add(obj); } catch (Exception) { throw; } }
public IActionResult Create(Role role) { if (!ModelState.IsValid) { return(View(role)); } role.Name = role.Name.Trim(); _roleRepository.Add(role); return(RedirectToRoute("default", new { controller = "Role", action = "Index", id = role.SystemId })); }
public async Task Add(SerializedNotification serializedNotification, Guid bufferId, DateTimeOffset timeQueued, Guid bufferGovernorId, Guid notificationPipelineId) { NotificationBuffer buffer = await crudRepository.FindAsync <NotificationBuffer>(bufferId); if (buffer == null) { buffer = new NotificationBuffer(bufferId, bufferGovernorId, notificationPipelineId); crudRepository.Add(buffer); // TODO race condition - use AddOrUpdate instead } BufferedNotification notification = new BufferedNotification( id: Guid.NewGuid(), buffer: buffer, notificationClassName: serializedNotification.NotificationClassName, notificationJson: serializedNotification.NotificationJson, timeQueued: timeQueued ); crudRepository.Add(notification); }
public async Task <AccountContract> CreateAccount(string login, string password) { AccountContract acc = new AccountContract { Login = login, Password = L2Security.HashPassword(password) }; acc.AccountId = (int)await _accountCrudRepository.Add(acc); return(acc); }
public static async Task Store <TEntity, TKey>(this ICrudRepository <TEntity, TKey> repository, TEntity entity, TKey key) where TEntity : class { var entityInDb = await repository.GetTracking(key); if (entityInDb == default(TEntity)) { repository.Add(entity); } else { // syn with existing repository.SetValue(entityInDb, entity); } }
public async Task <User> RegisterNewUser(User user) { ValidateUser(user); if (string.IsNullOrWhiteSpace(user.Password)) { throw new ArgumentNullException(nameof(user.Password)); } await ValidateExistingUser(user.Email); user.Password = HashPassword(user.Password); var addedUser = await _userRepository.Add(_mapper.MapToEntity(user)); _logger.LogTrace("User added for email {email} with new id {id}", user.Email, addedUser.Id); return(_mapper.MapToResource(addedUser)); }
public IActionResult Edit(Domain.Entities.System system) { if (!ModelState.IsValid) { return(View(system)); } system.Name = system.Name.Trim(); if (system.SystemId == 0) { _systemRepository.Add(system); } else { _systemRepository.Update(system); } return(RedirectToRoute("default", new { action = "Index", controller = "System" })); }
public void AddDeleteTest() { int countOld = repository.Count; using (var transaction = new TransactionScope()) { repository.Add(toAdd); int countAfterAdding = repository.Count; Assert.IsTrue(countAfterAdding == countOld + 1); int lastId = repository.GetAll().Max(x => x.Id); repository.Delete(lastId); int countAfterDeleting = repository.Count; Assert.IsTrue(countAfterDeleting == countOld); transaction.Complete(); } }
protected async Task <ExternalEventRecord[]> PrepareRecordsAsync() { var externalEventIds = externalEvents.Values.Select(x => x.Id).ToArray(); var existingRecord = await GetExistingEventRecordsAsync(externalEventIds); var records = externalEvents.Values.Select(x => { var existing = existingRecord.FirstOrDefault(y => y.Id == x.Id); if (existing != null) { return(existing); } crudRepository.Add(x); return(x); }).ToArray(); externalEvents.Clear(); return(records); }
public void get_all() { _repository.Add(new Domain.Entities.System() { SystemId = 1, Name = "App 1" }); _repository.Add(new Domain.Entities.System() { SystemId = 2, Name = "App 2" }); _repository.Add(new Domain.Entities.System() { SystemId = 3, Name = "App 3" }); _repository.All.Should().HaveCount(3); }
public void Add(TEntity entity) { _decoratedRepository.Add(entity); AddEntityToCache(entity); }
public void Add<T>(T aggregate) where T : class, IAggregateRoot { crudRepository.Add(aggregate); }
public void index_get_system_roles() { var systemApp1 = new Domain.Entities.System() { SystemId = 1, Name = "App 1" }; var systemApp2 = new Domain.Entities.System() { SystemId = 2, Name = "App 2" }; _systemRepository.Add(systemApp1); _systemRepository.Add(systemApp2); var controller = new RoleController(_repository, _systemRepository); _repository.Add(new Role() { RoleId = 1, Name = "admin", SystemId = 1, System = systemApp1 }); _repository.Add(new Role() { RoleId = 2, Name = "user", SystemId = 1, System = systemApp1 }); _repository.Add(new Role() { RoleId = 3, Name = "adminTest", SystemId = 2, System = systemApp2 }); _repository.Add(new Role() { RoleId = 4, Name = "userTest", SystemId = 2, System = systemApp2 }); var result = controller.Index(2); result.Should().BeViewResult().ModelAs <RoleModel>().Roles.Should().HaveCount(2); result.Should().BeViewResult().ModelAs <RoleModel>().System.Name.Should().Be("App 2"); result.Should().BeViewResult().ModelAs <RoleModel>().Roles.First(p => p.RoleId == 4).Name.Should().Be("userTest"); }