public Task <bool> Handle(StealGemCommand request, CancellationToken cancellationToken) { var gems = _gemRepository.GetByUser(request.Target); var gem = gems.FirstOrDefault(); if (gem != null) { ValidationHelper.ValidateUser(request.Request, out var userGuid, out var userRole); var user = _userRepository.GetById(userGuid); var cardsInPossession = _cardRepository.GetByUserAndCardType(userGuid, CardType.STEAL_GEM); if (!cardsInPossession.Any()) { throw new InvalidOperationException("No user cards of specified type have been found"); } gem.Message += "\n Stolen from: " + gem.To.FirstName; gem.To = user; _gemRepository.Save(gem); _cardRepository.Delete(cardsInPossession.FirstOrDefault().Id); return(Task.FromResult(true)); } else { return(Task.FromResult(false)); } }
public Task <bool> Handle(ReviveCommand request, CancellationToken cancellationToken) { ValidationHelper.ValidateUser(request.Request, out var userGuid, out var userRole); var user = _userRepository.GetById(userGuid); var cardsOfUser = _cardRepository.GetByUserAndCardType(userGuid, CardType.REVIVE); if (!cardsOfUser.Any()) { throw new InvalidOperationException("No user cards of specified type have been found"); } var graveyardGems = _gemRepository.GetByUser(Guid.Parse("0a9c40cd-34f5-439c-ad3c-0946aea1e5ea")); if (graveyardGems.Any()) { var firstGemFromGraveyard = graveyardGems.FirstOrDefault(); firstGemFromGraveyard.To.Id = user.Id; _gemRepository.Save(firstGemFromGraveyard); var card = cardsOfUser.FirstOrDefault(); _cardRepository.Delete(card.Id); return(Task.FromResult(true)); } else { return(Task.FromResult(false)); } }
public Task <bool> Handle(StealCardCommand request, CancellationToken cancellationToken) { var targetCards = _cardRepository.GetByUserAndCardType(request.Target, request.Card); if (!targetCards.Any()) { throw new InvalidOperationException("No target user cards of specified type have been found"); } else { ValidationHelper.ValidateUser(request.Request, out var userGuid, out var userRole); var user = _userRepository.GetById(userGuid); var userCards = _cardRepository.GetByUserAndCardType(userGuid, CardType.STEAL_CARD); if (userCards.Any()) { var card = targetCards.FirstOrDefault(); card.Owner = user; _cardRepository.Save(card); // Use up card _cardRepository.Delete(userCards.FirstOrDefault().Id); return(Task.FromResult(true)); } throw new InvalidOperationException("No user cards of specified type have been found"); } }
public async Task <CardViewDTO> Delete(int id, Guid userId) { if (id != null) { Card card = await _cardRepository.GetOne(id); Column column = await _columnRepository.GetOne(card.ColumnId); var reduceResult = await _sortService.ReduceAfterDeleteAsync(id); var result = await _cardRepository.Delete(id); var history = await _historyService.CreateHistoryObject( UserActions.DeleteCard, userId, card.Title, null, null, column.BoardId ); var mapperResult = _mapper.Map <Card, CardViewDTO>(result); return(mapperResult); } else { throw new Exception("Empty card id"); } }
public async Task <IActionResult> DeleteConfirmed(Guid id) { Card card = _context.GetCardByCardId(id); _context.Delete(card); return(RedirectToAction("Index")); }
public IActionResult DeleteCard(string id) { var status = false; string message = ResultState.Delete_FALSE; try { var result = _CardRepository.Delete(id); //xoa lun cac menh gia var menhgia = _menhgiaRepository.MenhGias().Where(x => x.cardId == id); foreach (var mg in menhgia) { _menhgiaRepository.Delete(mg.Id); } _CardRepository.SaveChange(); status = true; message = ResultState.Delete_SUCCESS; } catch (Exception e) { message = e.Message; } return(Json(new { status = status, message = message })); }
public Task <bool> Handle(DoubleSendCommand request, CancellationToken cancellationToken) { ValidationHelper.ValidateUser(request.Request, out var userGuid, out var userRole); var user = _userRepository.GetById(userGuid); var cardsOfUser = _cardRepository.GetByUserAndCardType(userGuid, CardType.DOUBLE_SEND); if (!cardsOfUser.Any()) { throw new InvalidOperationException("No user cards of specified type have been found"); } if (user.GemsToGive >= 0) { user.GemsToGive = user.GemsToGive > 0 ? user.GemsToGive : 1; user.GemsToGive *= 2; _userRepository.Save(user); var card = cardsOfUser.FirstOrDefault(); _cardRepository.Delete(card.Id); return(Task.FromResult(true)); } else { return(Task.FromResult(false)); } }
public async Task <Unit> Handle(DeleteCardCommand request, CancellationToken cancellationToken) { Card card = await _repository.GetSingle(request.CardId); await _repository.Delete(card); return(Unit.Value); }
public void Delete_WithValidInput_CardInTable() { var CardsList = repo.Get(); var firstCard = CardsList.First(); var res = repo.Delete(firstCard.ID); //var result = repo.GetByID(firstCard.ID); Assert.IsTrue(res); }
public async Task <bool> DeleteCardItemAsync(CardViewModel phoneToDelete) { var card = _mapper.Map <CardViewModel, Card>(phoneToDelete); _cardRepository.Delete(card); await _cardRepository.CommitAsync(); return(true); }
public async Task <Unit> Handle(DeleteCardCommand request, CancellationToken cancellationToken) { var card = await _cardRepository.GetAsync(request.Id); _cardRepository.Delete(card); await _cardRepository.UnitOfWork.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task Delete(Guid id) { var card = await _cardRepository.Get(id); if (card == null) { throw new Exception("card is not exist!"); } await _cardRepository.Delete(id); }
public async Task <IActionResult> DeleteCard([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _repository.Delete(id); return(Ok()); }
public ExecuteResult <CardInfoResponse> UnBinding(BindingRequest request) { throw new NotSupportedException("不支持该方法"); if (request == null || request.AuthUser == null) { return(new ExecuteResult <CardInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "参数错误" }); } var entities = _cardRepository.GetListForUserId(request.AuthUser.Id, CardType.YintaiMemberCard, DataStatus.Normal).ToList(); if (entities.Count == 0) { return(new ExecuteResult <CardInfoResponse>(null) { StatusCode = StatusCode.ClientError, Message = "你还没有绑定银泰卡,请您先绑定" }); } if (entities.Count > 1) { return(new ExecuteResult <CardInfoResponse>(null) { StatusCode = StatusCode.InternalServerError, Message = "服务器开小差了,请您等等再试" }); } var entity = entities[0]; using (var ts = new TransactionScope()) { var delEntity = _cardRepository.GetItem(entity.Id); delEntity.UpdatedDate = DateTime.Now; delEntity.UpdatedUser = request.AuthUser.Id; delEntity.Status = (int)DataStatus.Deleted; _cardRepository.Delete(delEntity); _userService.SetCardBinder(entity.User_Id, false); ts.Complete(); } return(new ExecuteResult <CardInfoResponse>(null) { StatusCode = StatusCode.Success, Message = "解除绑定成功" }); }
public ActionResult Delete(string id) { var card = _repository.FindByCondition(e => e.Id == id).FirstOrDefault(); if (card == null) { _logger.LogInformation($"Card for id {id} does not exists!"); return(NotFound()); } _repository.Delete(card); _repository.Save(); return(NoContent()); }
public Task <bool> Handle(SelfHugCommand request, CancellationToken cancellationToken) { var gemsList = new List <Gem>(); ValidationHelper.ValidateUser(request.Request, out var userGuid, out var userRole); var user = _userRepository.GetById(userGuid); var cardsOfUser = _cardRepository.GetByUserAndCardType(userGuid, CardType.SELF_HUG); if (!cardsOfUser.Any()) { throw new InvalidOperationException("No user cards of specified type have been found"); } if (user.GemsToGive >= request.GemsToGive) { for (int i = 0; i < request.GemsToGive; i++) { var newGuid = Guid.NewGuid(); var gem = new Gem() { Id = newGuid, From = user, To = user, Message = user.FirstName + " gave a gem to themselves" }; gemsList.Add(gem); user.GemsToGive = user.GemsToGive - 1; } _gemRepository.Save(gemsList); _userRepository.Save(user); var card = cardsOfUser.FirstOrDefault(); _cardRepository.Delete(card.Id); return(Task.FromResult(true)); } else { return(Task.FromResult(false)); } }
public Task <bool> Handle(DoubleReceiveCommand request, CancellationToken cancellationToken) { var gemsList = new List <Gem>(); ValidationHelper.ValidateUser(request.Request, out var userGuid, out var userRole); var user = _userRepository.GetById(userGuid); var userTarget = _userRepository.GetById(request.Target); var cardsOfUser = _cardRepository.GetByUserAndCardType(userGuid, CardType.DOUBLE_RECEIVE); if (!cardsOfUser.Any()) { throw new InvalidOperationException("No user cards of specified type have been found"); } var receivedGemsFromTargetThisWeek = _gemRepository.GetByWeek(request.Week).Where(x => x.From != null).Where(x => x.From.Id == userTarget.Id); if (receivedGemsFromTargetThisWeek.Any()) { for (int i = 0; i < receivedGemsFromTargetThisWeek.Count(); i++) { var newGuid = Guid.NewGuid(); var gem = new Gem() { Id = newGuid, From = userTarget, To = user, Message = user.Name + " doubled the number of gems he/she was given from " + userTarget.Name }; gemsList.Add(gem); } _gemRepository.Save(gemsList); _userRepository.Save(user); var card = cardsOfUser.FirstOrDefault(); _cardRepository.Delete(card.Id); return(Task.FromResult(true)); } else { return(Task.FromResult(false)); } }
public async Task Delete(int id) { var entity = await GetById(id); if (entity == null) { throw new ArgumentNullException(nameof(entity)); } await _repository.Delete(entity); }
public ActionResult GetAllCardsAndValidateMaledictionCard(int week) { var ActiveMaledictionCards = _cardRepository.GetAll().Where(x => x.IsActive && x.CardType == CardType.MALEDICTION); if (ActiveMaledictionCards.Any()) { foreach (var activeMaledictionCard in ActiveMaledictionCards) { if (week > activeMaledictionCard.Week) { _cardRepository.Delete(activeMaledictionCard.Id); } } } var cards = _cardRepository.GetAll(); return(Ok(cards)); }
public async Task <DeleteCardCommandResult> Handle(DeleteCardCommand request, CancellationToken cancellationToken) { DeleteCardCommandResult result = new DeleteCardCommandResult(); result.ResultObject = new ServiceResult <DeleteCardCommandResultItem>(); result.ResultObject.Success = false; result.ResultObject.ServiceMessageList = new List <ServiceMessage>(); result.ResultObject.Data = new DeleteCardCommandResultItem(); try { var validator = new DeleteCardCommandValidator(); var validationResult = validator.Validate(request); if (validationResult.IsValid) { Card card = new Card(); card.CardId = request.CardId; _cardRepository.Delete(card); result.ResultObject.Success = true; } else { result.ResultObject.Success = false; } } catch (Exception ex) { result.ResultObject.ServiceMessageList.Add(new ServiceMessage() { ServiceMessageType = eServiceMessageType.Error, UserFriendlyText = "An error occured", LogText = "BoardService.GetBoardSwimLanes() method error message: " + ex.Message, SystemException = ex }); } return(result); }
public async Task <IActionResult> Delete(int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _repository.Delete(id); switch (result) { case OpsStatus.Failed: return(StatusCode(500)); case OpsStatus.TargetNotFound: return(BadRequest()); default: return(StatusCode(204)); } }
public async Task <object> Delete(int id) { Card card = new Card(); try { card = _cardRepository.Delete(id); } catch (Exception ex) { result = false; error = ex.Message; } return(new SingleResponse <Card> { Message = "Card deleted successfully", DidError = false, ErrorMessage = string.Empty, Token = string.Empty, Model = card }); }
public Task <bool> Handle(RobinHoodCommand request, CancellationToken cancellationToken) { var sourceUserGems = _gemRepository.GetByUser(request.Source); var targetUserGems = _gemRepository.GetByUser(request.Target); ValidationHelper.ValidateUser(request.Request, out var userGuid, out var userRole); if (!sourceUserGems.Any()) { throw new InvalidOperationException("The user from whom you want to steal the gems has none available"); } var cardsInHand = _cardRepository.GetByUserAndCardType(userGuid, CardType.ROBIN_HOOD); if (!cardsInHand.Any()) { throw new InvalidOperationException("No user cards of specified type have been found"); } var sourceUserGemsList = sourceUserGems.ToList(); var targetUserGemsList = targetUserGems.ToList(); if (sourceUserGemsList.Count > targetUserGemsList.Count) { var gem = sourceUserGemsList[0]; gem.Message += " \n [Originally to " + gem.To.FirstName + "]"; gem.To.Id = request.Target; _gemRepository.Save(gem); // Use card _cardRepository.Delete(cardsInHand.FirstOrDefault().Id); return(Task.FromResult(true)); } return(Task.FromResult(false)); }
private string MaledictionCardGemsDivert(Gem gems, string msg) { var ActiveMaledictionCards = _cardRepository.GetAll().Where(x => x.IsActive && x.CardType == CardType.MALEDICTION); if (ActiveMaledictionCards.Any()) { foreach (var activeMaledictionCard in ActiveMaledictionCards) { if (gems.Week > activeMaledictionCard.Week) { _cardRepository.Delete(activeMaledictionCard.Id); continue; } if (gems.To.Id == activeMaledictionCard.TargetPlayerGuid) { gems.To = _userRepository.GetAll().SingleOrDefault(x => x.Name == "Graveyard"); msg = "The gem has been diverted to the graveyard since the user was spelled by the malediction card!"; } } } return(msg); }
public async Task <int> Invoke(UpdateDeckParams param) { var oldDeck = deckRepository.FindStaticById(param.NewDeck.Deck_Id); try { var mappedOldCards = oldDeck.Cards; var newDeck = param.NewDeck; if (oldDeck.Icon != newDeck.Icon) { var fileMD5 = _authUtils.GetMd5HashString(newDeck.Icon.ToString()); var filePath = _authUtils.GetFilePathFromMD5(fileMD5); _fileRepository.Insert(new File { File_Id = newDeck.Icon, Md5 = fileMD5, Path = filePath, Size = 0, Type = "", }); } //update entries oldDeck.Category_Name = newDeck.Category_Name; oldDeck.Icon = newDeck.Icon; oldDeck.Title = newDeck.Title; oldDeck.Description = newDeck.Description; oldDeck.Is_Private = newDeck.Is_Private; oldDeck.Available_Quick_Train = newDeck.Available_Quick_Train; oldDeck.LastUpdate = DateTime.Now; var cardsToAdd = SortCardsToAdd(mappedOldCards, param.NewDeck.Cards); var cardsToDelete = SortCardsToDelete(mappedOldCards, param.NewDeck.Cards); var cardsToUpdate = SortCardsToUpdate(mappedOldCards, param.NewDeck.Cards); if (cardsToAdd.Count != 0) { foreach (Card card in cardsToAdd) { card.Parent_Deck_Id = param.NewDeck.Deck_Id; } await cardRepository.InsertAsync(cardsToAdd); } if (cardsToDelete.Count != 0) { cardRepository.Delete(cardsToDelete); foreach (Card card in cardsToDelete) { oldDeck.Cards.Remove(card); } } if (cardsToUpdate.Count != 0) { foreach (Card card in cardsToUpdate) { card.Parent_Deck_Id = newDeck.Deck_Id; } await cardRepository.UpdateAsync(cardsToUpdate); } deckRepository.Save(); return(0); } catch (Exception e) { deckRepository.Delete(param.NewDeck.Deck_Id); await deckRepository.Insert(deckRepository.FindStaticById(param.NewDeck.Deck_Id)); deckRepository.Save(); return(1); } }
public void DeleteCard(int id) { Maybe <Card> foundcard = GetCardById(id); cardRepo.Delete(foundcard.Value); }
public IActionResult Delete(int id) { repo.Delete(id); return(Ok()); }
// xóa lun card public Card DeleteCard(int cardId) { DeleteFullContentCard(cardId); return(_cardRepository.Delete(cardId)); }
public int Delete(int id) { return(cardsRepository.Delete(id)); }