public ActionResult Post([FromBody] Source source) { if (source.Id != null && _sourceRepository.Exists(source.Id)) { return(BadRequest($"Source with Id of {source.Id} already exists")); } _sourceRepository.Add(source); return(Created($"/api/source/{source.Id}", source)); }
public void Seed() { foreach (var role in Roles) { if (!roleRepository.Exists(c => c.Name == role.Name)) { roleRepository.Save(role); } } }
public static bool Exists <TEntity, TKey>(this IRepository <TEntity, TKey> instance, TKey id) where TEntity : IIdentifiable <TKey> { if (instance.IsNull()) { throw new ArgumentNullException(nameof(instance)); } return(instance.Exists(id, out TEntity entity)); }
public void Seed() { foreach (var client in Clients) { if (!clientRepository.Exists(c => c.Name == client.Name)) { clientRepository.Save(client); } } }
public void TryGet_Should_Return_True_If_Item_Exists(IRepository <Contact, string> repository) { var contact = new Contact { Name = "Test User", ContactTypeId = 1 }; repository.Add(contact); repository.Exists(contact.ContactId).ShouldBeTrue(); }
public async Task <ResultDto <BaseDto> > AddReview(ReviewModel reviewModel, ClaimsPrincipal user) { var result = new ResultDto <BaseDto>() { Error = null }; //sprawdzam czy uzytkownik istnieje string userId = await _userManager.GetId(user); if (string.IsNullOrEmpty(userId)) { result.Error = "Autor poradnika nie został odnaleziony"; return(result); } //sprawdzam czy film istnieje bool exists = await _movieRepo.Exists(x => x.Id == reviewModel.MovieId); if (!exists) { result.Error = "Film o takim id nie istnieje"; return(result); } //sprawdzam czy recenzja danego filmu istnieje exists = await _reviewRepo.Exists(x => x.UserId == userId && x.MovieId == reviewModel.MovieId); if (exists) { result.Error = "Recenzja została już stworzona"; return(result); } //tworze recenzje i zapisuje w bazie danych var review = new Review() { Score = reviewModel.Score, Content = reviewModel.Content, UserId = userId, MovieId = reviewModel.MovieId, Created = DateTime.Now }; try { await _reviewRepo.Add(review); } catch (Exception e) { result.Error = e.Message; } return(result); }
/// <summary> /// Deletes a forum /// </summary> /// <param name="repository"> /// The repository. /// </param> /// <param name="forumID"> /// The forum ID. /// </param> /// <returns> /// Indicate that forum has been deleted /// </returns> public static bool Delete(this IRepository <Forum> repository, [NotNull] int forumID) { if (repository.Exists(f => f.ParentID == forumID)) { return(false); } repository.DbFunction.Scalar.forum_delete(ForumID: forumID); return(true); }
private void ValidateAnimal(string animalName) { if (string.IsNullOrEmpty(animalName)) { throw new Exception("An user and animal names should be informed to adopt the animal."); } if (!_animalRepository.Exists(animalName)) { throw new Exception("Animal doesn't exist"); } }
public PersonVO Update(PersonVO person) { if (!iRepository.Exists(person.Id)) { return(null); } var personEntity = converter.Parse(person); personEntity = iRepository.Update(personEntity); return(converter.Parse(personEntity)); }
private void ValidateUser(string userNickname) { if (string.IsNullOrEmpty(userNickname)) { throw new Exception("An user name should be informed to adopt the animal."); } if (!_userRepository.Exists(userNickname)) { throw new Exception("User doesn't exist"); } }
/// <summary> /// Deletes a Forum and Moves the Content to a new Forum /// </summary> /// <param name="repository"> /// The repository. /// </param> /// <returns> /// Indicates that forum has been deleted /// </returns> public static bool Move(this IRepository <Forum> repository, [NotNull] int oldForumId, [NotNull] int newForumId) { CodeContracts.VerifyNotNull(repository); if (repository.Exists(f => f.ParentID == oldForumId)) { return(false); } BoardContext.Current.GetRepository <Forum>().UpdateOnly( () => new Forum { LastMessageID = null, LastTopicID = null }, f => f.ID == oldForumId); BoardContext.Current.GetRepository <Active>().UpdateOnly( () => new Active { ForumID = newForumId }, f => f.ForumID == oldForumId); BoardContext.Current.GetRepository <NntpForum>().UpdateOnly( () => new NntpForum { ForumID = newForumId }, f => f.ForumID == oldForumId); BoardContext.Current.GetRepository <WatchForum>().UpdateOnly( () => new WatchForum { ForumID = newForumId }, f => f.ForumID == oldForumId); BoardContext.Current.GetRepository <ForumReadTracking>().UpdateOnly( () => new ForumReadTracking { ForumID = newForumId }, f => f.ForumID == oldForumId); // -- Move topics, messages and attachments var topics = BoardContext.Current.GetRepository <Topic>().Get(t => t.ForumID == oldForumId); topics.ForEach( topic => BoardContext.Current.GetRepository <Topic>().Move(topic.ID, oldForumId, newForumId, false, 0)); BoardContext.Current.GetRepository <ForumAccess>().Delete(x => x.ForumID == oldForumId); BoardContext.Current.GetRepository <UserForum>().UpdateOnly( () => new UserForum { ForumID = newForumId }, f => f.ForumID == oldForumId); BoardContext.Current.GetRepository <Forum>().Delete(x => x.ID == oldForumId); return(true); }
public async Task <IActionResult> Update(Company company) { if (!await _companiesRepository.Exists(x => x.Id == company.Id)) { return(NotFound()); } var result = await _companiesRepository.UpdateAsync(company); return(Ok(result) .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, result.Id.ToString()))); }
public IHttpActionResult Post(AssetWriteModel model) { if (model == null) { return(BadRequest(Constants.MISSING_MESSAGE_BODY)); } if (!_productRepo.Exists(model.ProductId.Value)) { return(BadRequest(UNKNOWN_PRODUCT)); } var dto = MapToDto(model, createdBy: _jwt.UserId); long id = _assetRepo.Insert(dto); // Refetch the data. dto = _assetRepo.GetById(id); var readModel = MapToModel(dto); return(CreatedAtRoute(nameof(GetAssetById), new { id = readModel.Id }, readModel)); }
public CommandResponse Handle(CreateAccount command) { if (_repository.Exists <AccountAggregate.BankAccount>(command.AccountId)) { throw new InvalidOperationException("An account with this ID already exists"); } var account = new AccountAggregate.BankAccount(command.AccountId, command.HolderName, new AccountCreated(command.AccountId, command.HolderName)); _repository.Save(account); return(command.Succeed()); }
public void TryFind_Should_Return_True_Which_Satisfies_Predicate(IRepository <Contact, string> repository) { for (var i = 1; i <= 3; i++) { var contact = new Contact { Name = "Test User " + i }; repository.Add(contact); } repository.Exists(p => p.Name == "Test User 1").ShouldBeTrue(); }
public IActionResult Put(string id, [FromBody] UpdateInvoice updateInvoice) { if (updateInvoice == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!invoiceRepository.Exists(id)) { return(NotFound()); } invoiceRepository.Update(updateInvoiceMapper.ToDomain(updateInvoice, id)); return(NoContent()); }
protected override void OnVerify(IRepository <T> repository) { if (null == repository) { throw new ArgumentNullException("repository"); } if (repository.Exists(AlphaDecimal.Random())) { throw new RepositoryTestException(Resources.Repository_ExpectWhenDoesNotExist_ExceptionMessage.FormatWith("Exists", "false")); } }
public async Task <IActionResult> Update(Person person) { if (!await _peopleRepository.Exists(x => x.Id == person.Id)) { return(NotFound()); } var result = await _peopleRepository.UpdateAsync(person); return(Ok(result) .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, result.Id.ToString()))); }
public Tag AddTag(int articleId, int tagId) { if (_repository.Exists(e => e.ArticleId == articleId && e.TagId == tagId)) { throw new Comm100Exception(200009, "关系已经存在,不允许重复添加!"); } _repository.Insert(new ArticleTag() { ArticleId = articleId, TagId = tagId }); return(TagDomainService.Get(tagId)); }
public async Task <IActionResult> Put(string id, [FromBody] TodoItem item) { if (item == null) { return(BadRequest()); } if (!_todoItemsRepository.Exists(i => i.Id == id)) { return(NotFound()); } if (item.Id == null || item.Id != id) { item.Id = id; } await _todoItemsRepository.UpdateAsync(item); return(NoContent()); }
protected override void OnVerify(IRepository <T> repository) { if (null == repository) { throw new ArgumentNullException("repository"); } if (repository.Exists("urn://example.com/" + Guid.NewGuid())) { throw new RepositoryTestException(Resources.Repository_ExpectWhenDoesNotExist_ExceptionMessage.FormatWith("Exists", "false")); } }
/// <summary> /// Adds a buddy request. (Should be approved later by "ToUserID") /// </summary> /// <param name="repository"> /// The repository. /// </param> /// <param name="fromUserId"> /// The from User Id. /// </param> /// <param name="toUserId"> /// The to User Id. /// </param> /// <returns> /// The name of the second user + Whether this request is approved or not. /// </returns> public static bool AddRequest( this IRepository <Buddy> repository, [NotNull] int fromUserId, [NotNull] int toUserId) { CodeContracts.VerifyNotNull(repository); if (repository.Exists(x => x.FromUserID == fromUserId && x.ToUserID == toUserId)) { return(false); } if (repository.Exists(x => x.FromUserID == toUserId && x.ToUserID == fromUserId)) { repository.Insert( new Buddy { FromUserID = fromUserId, ToUserID = toUserId, Approved = true, Requested = DateTime.UtcNow }); repository.UpdateOnly( () => new Buddy { Approved = true }, b => b.FromUserID == toUserId && b.ToUserID == fromUserId); return(true); } repository.Insert( new Buddy { FromUserID = fromUserId, ToUserID = toUserId, Approved = false, Requested = DateTime.UtcNow }); return(false); }
public void InsertOpening(Opening aOpening) { CheckPermission(Permission.EDIT_BLUEPRINT); blueprint.InsertOpening(aOpening); if (!templates.Exists(aOpening.getTemplate())) { templates.Add(aOpening.getTemplate()); } repository.Modify(blueprint); HasBeenModify = true; }
public void Authorize() { Authorization authorization = controller.Create(model); Assert.True(authorizationRepository.Exists(authorization)); Assert.AreEqual(client, authorization.Client); Assert.AreEqual(connection, authorization.Connection); Assert.NotNull(authorization.AccessToken); ValidateAccessToken(authorization); }
public void DeleteUserRole() { Role roleModel = new Role { Name = "role name", Description = "description role" }; Role role = controller.Add(roleModel); UserRole userRole = controller.AddUserRole(role, user); controller.DeleteUserRole(userRole.Id); Assert.False(userRoleRepository.Exists(userRole)); }
public async Task <bool> DeleteSala(Guid id) { var sala = await _context.Exists(id); if (!sala) { return(sala); } await _context.Delete(id); return(sala); }
private async Task <Result> Validate(CreateProduct command) { var existsWithSku = await repository.Exists(x => x.Sku == command.Sku); if (existsWithSku) { return(CatalogResults.ProductAlreadyExistsWithSku); } var deptoExists = await departamentRepository.EnsureExists(command.DepartamentId); return(deptoExists); }
public List <Error> ValidateForCreation(Driver driver) { var res = ValidateFields(driver); if (!res.Any() && _repository.Exists(driver.Name)) { res.Add(new Error { Problem = "Already exists", Where = nameof(Driver) }); } return(res); }
private bool Exists() { _idExistsTask.Read(); try { _idExistsTask._exists.Synchron = _repository.Exists(_idExistsTask._identifier.Cyclic); return(true); } catch (Exception exception) { throw exception; } }
/// <summary> /// 检测邮箱是否注册 /// </summary> /// <param name="model">用户注册模型</param> /// <returns></returns> public bool IsRegiste(UserRegisterModel model) { IRepository <Account> accountRep = FBS.Factory.Factory <IRepository <Account> > .GetConcrete <Account>(); if (accountRep.Exists(new Specification <Account>(a => a.Email == model.Email))) { return(true); } else { return(false); } }
public void TryGet_Should_Return_True_If_Item_Exists(IRepository<Contact, string> repository) { var contact = new Contact { Name = "Test User", ContactTypeId = 1 }; repository.Add(contact); repository.Exists(contact.ContactId).ShouldBeTrue(); }
public void TryGet_Should_Return_False_If_Item_Does_Not_Exists(IRepository<Contact, string> repository) { repository.Exists(string.Empty).ShouldBeFalse(); }
public void TryFind_Should_Return_False_When_Specification_Does_Not_Match(IRepository<Contact, string> repository) { repository.Exists(new Specification<Contact>(p => p.Name == "DOES NOT EXIST")).ShouldBeFalse(); }
public void TryFind_Should_Return_False_When_Predicate_Does_Not_Match(IRepository<Contact, string> repository) { repository.Exists(p => p.Name == "DOES NOT EXIST").ShouldBeFalse(); }
public void TryFind_Should_Return_True_Which_Satisfies_Specification(IRepository<Contact, string> repository) { for (var i = 1; i <= 3; i++) { var contact = new Contact { Name = "Test User " + i }; repository.Add(contact); } repository.Exists(new Specification<Contact>(p => p.Name == "Test User 1")).ShouldBeTrue(); }