public virtual async Task AddAsync(TViewModel viewModel) { var entity = _mapper.GetEntity(viewModel); entity = SetUserOnAdd(entity, _serviceUser); await _repository.AddAsync(entity, _autoSave); }
public virtual async Task <TEntity> AddAsync(TEntity entity) { await _entityRepository.AddAsync(entity); await _entityRepository.SaveChangesAsync(); return(entity); }
public virtual async Task <IActionResult> Create([FromBody] TViewModelCadastro model) { var objectToCreate = _mapper.Map <TViewModelCadastro, T>(model); await _repositoryBase.AddAsync(objectToCreate); return(StatusCode(201)); }
public virtual Task AddAsync(TEntity entity) { if (entity.IsValid()) { return(_repositoryBase.AddAsync(entity)); } throw new Exception("Dados invalidos!"); }
public static async Task <QuestionType> AddQuestionTypeAsync(IRepositoryBase <QuestionType> repo, string name) { var qType = new QuestionType { Name = name }; return(await repo.AddAsync(qType)); }
public virtual async Task AddAsync(T model, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null) { _cache?.Add(model.Id.ToString(), model); await _dbSet.AddAsync(model); await _db.SaveChangesAsync(); _rep?.AddAsync(model); }
public Task RegisterUserAsync(User user) { if (user is MrGreenUser mrGreenUser) { return(_userRepo.AddAsync(mrGreenUser)); } throw new WrongUserParameterTypeException(nameof(MrGreenRegisterStrategy)); }
public static async Task <Question> AddQuestionAsync(IRepositoryBase <Question> repo, string questionName, QuestionType questionType, Poll poll) { var question = new Question { Name = questionName, Type = questionType, Poll = poll }; return(await repo.AddAsync(question)); }
public async Task <IActionResult> Create([Bind("SupplierId,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax,HomePage")] Supplier supplier) { if (ModelState.IsValid) { await repo.AddAsync(supplier); return(RedirectToAction(nameof(Index))); } return(View(supplier)); }
public static async Task <Poll> AddPollAsync(IRepositoryBase <Poll> repo, string name, string description, DateTimeOffset expirationDate) { var poll = new Poll { Name = name, Description = description, CreationDate = DateTimeOffset.Now, ExpirationDate = expirationDate }; return(await repo.AddAsync(poll)); }
public async Task <IActionResult> Create([Bind("PkId,Title,Description,Image,IsEdited,Created,Updated,FkUserId")] AspNetPosts aspNetPosts) { if (ModelState.IsValid) { aspNetPosts.Created = DateTime.Now; aspNetPosts.FkUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); await repo.AddAsync(aspNetPosts); return(RedirectToAction(nameof(Index))); } return(View()); }
public async Task <TEntity> AddAsync(TEntity entity) { var validationResult = _validator.Validate(entity); if (!validationResult.IsValid) { throw new ValidationException(this.ValidationResultToString(validationResult)); } await _repo.AddAsync(entity); await _repo.SaveChanges(); return(entity); }
public async Task AddAsync_AddAnswerToQuestion_ShouldAddQuestions() { var poll = await DataAccessHelpers.AddPollAsync(_pollRepo, "Event 1", "Short description", DateTimeOffset.Now.AddDays(5.0)); var qType = await DataAccessHelpers.AddQuestionTypeAsync(_questionTypeRepo, "Simple"); var question = await DataAccessHelpers.AddQuestionAsync(_questionRepo, "Do you want to sleep?", qType, poll); var afirmativeAnswer = new Answer { Name = "Yes", Question = question }; var result = await _answerRepo.AddAsync(afirmativeAnswer); Assert.That(result, Is.Not.Null); }
public async Task AddAsync_AddNewPoll_ShouldInsertIntoDatabase() { var poll = new Poll { Name = "Summer event", Description = "This is a short description for the summer event", CreationDate = DateTimeOffset.Now, ExpirationDate = DateTimeOffset.Now.AddDays(5.0) }; var pollResult = await _repo.AddAsync(poll); Assert.That(pollResult.Name, Is.EqualTo(poll.Name)); }
public async Task ContactAddAsyncOk() { var contactType = ContactTypeFaker.GetContactTypeOk(); var count = await _db.ContactTypes.CountAsync(); await _contactTypeRepository.AddAsync(contactType); var rowsAffected = await _contactTypeRepository.CommitAsync(); var contactFromDatabase = await _contactTypeRepository.GetByIdAsync(contactType.Id); Assert.True(rowsAffected.QuantityOfRecordsAffecteds == 1); Assert.NotNull(contactFromDatabase); }
public async Task AddAsync_AddNewQuestionToPoll_ShouldInsertQuestionIntoDatabase() { var poll = await DataAccessHelpers.AddPollAsync(_pollRepo, "Event 1", "Short description", DateTimeOffset.Now.AddDays(5.0)); var qType = await DataAccessHelpers.AddQuestionTypeAsync(_questionType, "Simple"); var question = new Question { Name = "Do you want to hang out this afternoon?", Type = qType, Poll = poll }; var insertedQuestion = await _questionRepo.AddAsync(question); Assert.That(insertedQuestion.Name, Is.EqualTo(question.Name)); }
public async Task <IActionResult> Create([Bind("ProductId,ProductName,SupplierId,CategoryId,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] Product product) { if (ModelState.IsValid) { await productRepo.AddAsync(product); return(RedirectToAction(nameof(Index))); } IEnumerable <Category> categories = await categoryRepo.GetAllAsync(); IEnumerable <Supplier> suppliers = await supplierRepo.GetAllAsync(); ViewData["CategoryId"] = new SelectList(categories, "CategoryId", "CategoryName", product.CategoryId); ViewData["SupplierId"] = new SelectList(suppliers, "SupplierId", "CompanyName", product.SupplierId); return(View(product)); }
public async Task <IActionResult> Get() { try { List <Cards> deckCards = new List <Cards>(); //get all cards foreach (Cards.Suits suit in Enum.GetValues(typeof(Cards.Suits))) { foreach (Cards.Kinds kind in Enum.GetValues(typeof(Cards.Kinds))) { deckCards.Add(new Cards(suit, kind)); } } //shuffle cards List <Cards> deckCardsShuffle = Shuffle(deckCards); Cards firstCard = deckCardsShuffle.FirstOrDefault(); Room room = new Room() { ID = Guid.NewGuid(), CardsPlayed = 1, DeckCards = deckCardsShuffle }; await roomRepository.AddAsync(room); DeckCardsResponse response = new DeckCardsResponse() { ID = room.ID, cardNumber = firstCard.ToString() }; return(Ok(response)); } catch (Exception) { return(StatusCode(500, "Internal server error")); } }
public async Task <OperationResult <Payment> > PaymentAsync(Payment payment) { try { if (await _repository.AddAsync(payment)) { return(new OperationResult <Payment> { Succeeded = true, StatusCode = System.Net.HttpStatusCode.OK }); } } catch (System.Exception ex) { _logger.LogError("CheapPaymentAsync", ex.Message, ex.InnerException.Message, ex.StackTrace); } return(new OperationResult <Payment> { Succeeded = true, StatusCode = System.Net.HttpStatusCode.InternalServerError }); }
public virtual async Task AddAsync(TEntity entity) { await _repository.AddAsync(entity); }
public async Task AddAsync(TEntity obj) { await _repository.AddAsync(obj); }
public async Task <Int32> AddAsync(TEntity obj) { return(await _repository.AddAsync(obj).ConfigureAwait(true)); }
public async Task <TEntity> AddAsync(TEntity entity) { var id = await _repository.AddAsync(entity); return(await _repository.GetAsync(id)); }
public async Task AddAsync(TEntity obj) { await _repository.AddAsync(obj).ConfigureAwait(true); }
public async Task <TEntity> AddAsync(TEntity entity) { await _repository.AddAsync(entity); return(entity); }
public async Task <TEntity> AddAsync(TEntity entity) { return(await repository.AddAsync(entity)); }
public virtual async Task <int> AddAsync(TEntity entity) { return(await _repository.AddAsync(entity)); }
public Task <TEntity> AddAsync(TEntity model) { return(_repository.AddAsync(model)); }
public virtual async Task CreateAsync(T entity) { await _entityRepository.AddAsync(entity); await _unitOfWork.CommitAsync(); }
public async Task AddEmployee(Employee employee) { await _employeesRepo.AddAsync(employee); }