public async Task <ActionResult <DealDto> > UpdateDeal( Guid dealId, [FromBody] UpdateDealRequestModel requestModel) { DealDto responseModel = await dealService.UpdateDeal( dealId, new UpdateDealDto { Name = requestModel.Name, Currency = requestModel.Currency, OriginalPrice = requestModel.OriginalPrice, Price = requestModel.Price, DealValidFrom = requestModel.DealValidFrom, DealValidTo = requestModel.DealValidTo, MarketUrl = requestModel.MarketUrl, BuyNowUrl = requestModel.BuyNowUrl, Gender = requestModel.Gender, DealType = requestModel.DealType, BrandId = requestModel.BrandId, IsActive = requestModel.IsActive, CouponCode = requestModel.CouponCode, Images = requestModel.Images.Select(i => imageWriter.UploadImage(i).Result) }); if (responseModel == null) { return(InvalidRequest()); } return(Ok(responseModel)); }
/// <summary> /// 同步出牌 /// </summary> /// <param name="dto"></param> private void dealBro(DealDto dto) { //移除出完的手牌 int userId = dto.UserId; int eventCode = -1; if (dto.UserId == Models.GameModel.MatchRoomDto.LeftId) { eventCode = CharacterEvent.REMOVE_LEFT_CARD; } else if (dto.UserId == Models.GameModel.MatchRoomDto.RightId) { eventCode = CharacterEvent.REMOVE_RIGHT_CARD; } else if (dto.UserId == Models.GameModel.UserDto.Id) { eventCode = CharacterEvent.REMOVE_MY_CARD; } //重新显示自己的手牌 Dispatch(AreaCode.CHARACTER, eventCode, dto.RemainCardList); //显示到桌面上 Dispatch(AreaCode.CHARACTER, CharacterEvent.UPDATE_SHOW_DESK, dto.selectCardList); //播放出牌音效 playDealAudio(dto.Type, dto.Weight); //关闭计时器 }
public async Task <ActionResult <DealDto> > CreateDeal([FromBody] CreateDealRequestModel requestModel) { DealDto responseModel = await dealService.CreateDeal( new CreateDealDto { Name = requestModel.Name, Currency = requestModel.Currency, OriginalPrice = requestModel.OriginalPrice, Price = requestModel.Price, DealValidFrom = requestModel.DealValidFrom, DealValidTo = requestModel.DealValidTo, MarketUrl = requestModel.MarketUrl, BuyNowUrl = requestModel.BuyNowUrl, Gender = requestModel.Gender, DealType = requestModel.DealType, BrandId = requestModel.BrandId, CouponCode = requestModel.CouponCode, Images = requestModel.Images.Select(i => imageWriter.UploadImage(i).Result) }); if (responseModel == null) { return(InvalidRequest()); } return(CreatedAtAction(nameof(CreateDeal), new { id = responseModel.Id }, responseModel)); }
/// <summary> /// 同步出牌 /// </summary> /// <param name="dto"></param> private void DealBro(DealDto dto) { //关闭出牌按钮 Dispatch(AreaCode.UI, UIEvent.HIDE_DEAL_BUTTON, null); //移除出完的手牌 int eventCode = -1; if (dto.userId == Model.gameModel.matchRoomDto.leftId) { eventCode = CharacterEvent.REMOVE_LEFT_CARD; } else if (dto.userId == Model.gameModel.matchRoomDto.rightId) { eventCode = CharacterEvent.REMOVE_RIGHT_CARD; } else if (dto.userId == Model.gameModel.UserDto.id) { eventCode = CharacterEvent.REMOVE_MY_CARD; } Dispatch(AreaCode.CHARACTER, eventCode, dto.remainCardList); //显示到桌面//出的牌放到正中间 Dispatch(AreaCode.CHARACTER, CharacterEvent.UPDATE_SHOW_DESK, dto.selectCardList); //播放音效 PlayDealAudio(dto.type, dto.weight); }
/// <summary> /// 出牌的处理 /// </summary> private void Deal(ClientPeer client, DealDto dto) { SingleExecute.Instance.Execute( delegate() { //玩家在线 if (user.IsOnLine(client) == false) { return; } int userId = user.GetIdByClient(client); if (userId != dto.userId) //DTO的ID可以用来做验证。 { return; } FightRoom room = fight.GetRoom(userId); //玩家出牌 //掉线 在线 if (room.LeaveUidList.Contains(userId)) { //自动出牌 Turn(room); } //玩家在线 bool canDeal = room.DealCard(dto.length, dto.type, dto.weight, userId, dto.selectCardList); if (canDeal == false) { //压不住 client.Send(OpCode.FIGHT, FightCode.DEAL_SRES, -1); return; } else { //发送给出牌者 client.Send(OpCode.FIGHT, FightCode.DEAL_SRES, 0); List <CardDto> remainCardList = room.GetPlayerCard(userId); dto.remainCardList = remainCardList; //广播 Brocast(room, OpCode.FIGHT, FightCode.DEAL_BRO, dto); //检测下 剩余牌 为0 就赢了 if (remainCardList.Count == 0) { //游戏结束 GameOver(userId, room); } else { //转换玩家 Turn(room); } } } ); }
/// <summary> /// 出牌的处理 /// </summary> private void deal(ClientPeer client, DealDto dto) { SingleExecute.Instance.Execute( delegate() { if (userCache.IsOnline(client) == false) { return; } //必须确保在线 int userId = userCache.GetId(client); if (userId != dto.UserId) { return; } FightRoom room = fightCache.GetRoomByUId(userId); //玩家出牌 //玩家已经中途退出 掉线 if (room.LeaveUIdList.Contains(userId)) { //直接转换出牌 turn(room); } //玩家还在 bool canDeal = room.DealCard(dto.Type, dto.Weight, dto.Length, userId, dto.SelectCardList); if (canDeal == false && room.roundModel.BiggestUId != userId) { //玩家出的牌管不上上一个玩家出的牌 client.Send(OpCode.FIGHT, FightCode.DEAL_SRES, -1); return; } else { //出牌成功 //广播 给所有的客户端 List <CardDto> remainCardList = room.GetPlayerModel(userId).CardList; dto.RemainCardList = remainCardList; brocast(room, OpCode.FIGHT, FightCode.DEAL_BRO, dto); //检测一下剩余手牌,如果手牌数为0,那就游戏结束了 if (remainCardList.Count == 0) { //游戏结束 gameOver(userId, room); } else { //转换出牌 turn(room); } } } ); }
public async Task <ActionResult <DealDto> > GetDeal(Guid dealId) { DealDto deal = await dealService.GetDealById(dealId); if (deal == null) { return(InvalidRequest()); } return(Ok(deal)); }
/// <summary> /// 出牌的处理 /// </summary> private void deal(ClientPeer client, DealDto dto) { SingleExecute.Instance.Execute(() => { if (!userCache.IsOnline(client)) { return; } int userId = userCache.GetId(client); if (userId != dto.UserId) { return; } FightRoom fightRoom = fightCache.GetRoomByUId(userId); //玩家如果掉线退出 if (fightRoom.LeaveUIdList.Contains(userId)) { //直接跳过 Turn(fightRoom); } bool canDel = fightRoom.DeadCard(dto.Type, dto.Weight, dto.Length, dto.UserId, dto.selectCardList); if (canDel == false) { //玩家出的牌管不上 client.Send(OpCode.FIGHT, FightCode.DEAL_SERS, -1); return; } else { //给自身客户端发送出牌成功的消息 client.Send(OpCode.FIGHT, FightCode.DEAL_SERS, 0); Brocast(fightRoom, OpCode.FIGHT, FightCode.END_TIMEING_BRO, userId); //检查一下剩余手牌数 List <CardDto> remainCard = fightRoom.GetPlayerModel(userId).CardList; //广播给所有客户端 dto.RemainCardList = remainCard; Brocast(fightRoom, OpCode.FIGHT, FightCode.DEAL_BRO, dto); TimeOutManager.Instance.RemoveEvent(userId); if (remainCard.Count == 0) { //游戏结束 gameOver(userId, fightRoom); } else { //转换出牌 Turn(fightRoom); } } }); }
private DealDto BiggestTimeOutDeal(int userId) { FightRoom fightRoom = fightCache.GetRoomByUId(userId); //检查一下剩余手牌数 List <CardDto> selectCard = fightRoom.getUserFirstCard(userId); fightRoom.RemoveCards(userId, selectCard); //广播给所有客户端 DealDto dealDto = new DealDto(selectCard, userId); dealDto.RemainCardList = fightRoom.getUserCards(userId); return(dealDto); }
public IHttpActionResult UpdateDeal(DealDto deal) { try { var updatedDeal = _dealService.UpdateDeal(deal); return(CreateResponse(updatedDeal)); } catch (Exception exception) { LogError(this.GetType(), exception.Message); return(CreateErrorResponse(exception.Message, exception)); } }
private void btnEditDeal_Click(object sender, RoutedEventArgs e) { DealDto item = dgDeal.SelectedItem as DealDto; if (item == null) { MessageBox.Show("Выберите запись для редактирования", "Редактирование сделок"); } AddDealWindow window = new AddDealWindow(); window.Load(item); window.ShowDialog(); btnRefresh_Click(sender, e); }
// // DEAL // public static DealDto Convert(Deal deal) { if (deal == null) { return(null); } DealDto dealDto = new DealDto(); dealDto.DealID = deal.DealID; dealDto.DateOfDeal = deal.DateOfDeal; dealDto.Commission = deal.Commission; dealDto.Position = Convert(DaoFactory.GetPositionDao().Get(deal.PositionID)); dealDto.Seeker = Convert(DaoFactory.GetJobSeekerDao().Get(deal.SeekerID)); return(dealDto); }
public static Deal Convert(DealDto dealDto) { if (dealDto == null) { return(null); } Deal deal = new Deal(); deal.DealID = dealDto.DealID; deal.DateOfDeal = dealDto.DateOfDeal; deal.Commission = dealDto.Commission; deal.PositionID = dealDto.Position.PositionID; deal.SeekerID = dealDto.Seeker.SeekerID; return(deal); }
public IHttpActionResult CreateDeal(DealDto dealDto) { if (!ModelState.IsValid) { return(BadRequest()); } var deal = Mapper.Map <DealDto, Deal>(dealDto); _context.Deals.Add(deal); _context.SaveChanges(); dealDto.DealId = deal.DealId; return(Created(new Uri(Request.RequestUri + "/" + deal.DealId), dealDto)); }
/// <summary> /// 发牌 /// </summary> private void Deal(ClientPeer client, DealDto dto) { SingleExecute.Instance.Execute(() => { if (UserCache.IsOnline(client) == false) { socketMsg.State = null; return; } int userId = UserCache.GetClientUserId(client); FightRoom room = FightCache.GetRoomByUId(userId); //玩家出牌、玩家掉线 if (room.LeaveUIdList.Contains(userId)) { Turn(room); } bool canDeal = room.DeadCard(dto.Type, dto.Weight, dto.Length, userId, dto.SelectCardList); if (canDeal == false) { socketMsg.State = FightCode.必须大于上次一次出牌; socketMsg.SubCode = FightCode.Deal_Result; client.Send(socketMsg); return; } else { //返回客户端出牌成功 socketMsg.State = FightCode.Success; socketMsg.SubCode = FightCode.Deal_Result; client.Send(socketMsg); //广播出牌结果 socketMsg.value = dto; BroCast(room, socketMsg, client); //检查剩余手牌 List <CardDto> remainCardList = room.GetPlayerModel(userId).CardList; if (remainCardList.Count == 0) { //游戏结束 GameOver(userId, room); } else { Turn(room); } } }); }
/// <summary> /// 出牌 /// </summary> /// <param name="clientPeer"></param> /// <param name="value"></param> private void Deal(ClientPeer clientPeer, DealDto dealDto) { SingleExcute.Instance.Excute( delegate() { //出牌者id int uid = dealDto.Uid; FightRoomModel room = fightRoomCache.GetFightRoomByUid(uid); if (room.EscapePlayerId.Contains(uid)) { //玩家已经退出房间 Turn(room, uid); } else { //玩家没有退出房间,判断玩家是否可以压过上一家出牌者 if (room.PlayCard(dealDto.Weight, dealDto.Type, dealDto.Length, dealDto.Uid, dealDto.Cards)) { //给玩家发送出牌成功消息 clientPeer.Send(OpCode.FIGHT, FightCode.DEAL_SRES, 0); //广播出牌成功消息 dealDto.RemainCards = room.GetPlayerModel(uid).CardDtos.Except(dealDto.Cards).ToList(); Brocast(room, OpCode.FIGHT, FightCode.DEAL_BRO, dealDto); //判断玩家是否还有手牌 if (!room.HasCard(uid)) { //没有手牌,结束游戏 GameOver(room, uid); } else { //还有手牌,转换出牌 Turn(room, uid); } } else { //无法压过上一家的牌,出牌失败的处理 clientPeer.Send(OpCode.FIGHT, FightCode.DEAL_SRES, -1); } } } ); }
private void btnDeleteDeal_Click(object sender, RoutedEventArgs e) { DealDto item = dgDeal.SelectedItem as DealDto; if (item == null) { MessageBox.Show("Выберите запись для удаления", "Удаление сделок"); } MessageBoxResult result = MessageBox.Show("Удалить сделку №" + item.DealID + "?", "Удаление сделок", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result != MessageBoxResult.Yes) { return; } ProcessFactory.GetDealProcess().Delete(item.DealID); btnRefresh_Click(sender, e); }
private void dealSelectCard() { List <CardDto> selectCardList = getSelectedCard(); DealDto dto = new DealDto(selectCardList, Models.GameModel.Id); // if (dto.IsRegular == false) { promptMsg.Change("Please select right hands", Color.red); Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, promptMsg); return; } else { socketMsg.Change(OpCode.FIGHT, FightCode.DEAL_CREQ, dto); Dispatch(AreaCode.NET, 0, socketMsg); } }
/// <summary> /// 出牌 /// </summary> private void DealCard() { List <CardDto> selectCards = GetSelectCards(); DealDto dealDto = new DealDto(selectCards, Caches.UserDto.Id); if (dealDto.IsRegular == false) { promptMsg.Change("请选择合理的手牌", Color.red); Dispatch(AreaCode.UI, UIEvent.PROMPT_PANEL_SHOW, promptMsg); Dispatch(AreaCode.UI, UIEvent.SHOW_OR_HIDE_DEAL_BTN, true); return; } else { socketMsg.Change(OpCode.FIGHT, FightCode.DEAL_CREQ, dealDto); Dispatch(AreaCode.NET, 0, socketMsg); } }
/// <summary> /// 出选中的牌 并发送给服务器 /// </summary> private void DealSelectCard() { List <CardDto> selectCardList = GetSelectCard(); DealDto dto = new DealDto(selectCardList, Model.gameModel.UserDto.id); //如果出牌不合法 if (dto.isRegular == false) { promptMsg.ChangeText("卡牌不对", Color.red); Dispatch(AreaCode.UI, UIEvent.PROMPTA_ANIM, promptMsg); return; } else //可以出牌 { socketMsg.Change(OpCode.FIGHT, FightCode.DEAL_CREQ, dto); Dispatch(AreaCode.NET, 0, socketMsg); } }
public IHttpActionResult AddNewDeal(DealDto deal) { try { if (deal == null) { return(CreateErrorResponse($"Parameter {nameof(deal)} cannot be null")); } var newDeal = _dealService.AddNewDeal(deal); return(CreateResponse(newDeal)); } catch (Exception exception) { LogError(this.GetType(), exception.Message); return(CreateErrorResponse(exception.Message, exception)); } }
public async Task <string> InsertDealDetails(DealDto DealDto, int Merchantid) { DateTime Timezone = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(Presentdate, TimeZoneInfo.Local.Id, DealDto.CountryTimezone); int ActiveDeallist = this.Repository.Where(m => m.EndDate >= Timezone) .Where(m => m.Status.Equals(1)) .Where(m => m.MerchantId == Merchantid).Count(); if (DealDto.StartDate > Timezone && DealDto.EndDate > DealDto.StartDate) { if (ActiveDeallist < 3) { await Repository.InsertAsync(new Deals { MerchantId = Merchantid, DealName = DealDto.DealName, DealCode = DealDto.DealCode, Country = DealDto.Countries, EnglishImage = DealDto.EnglishImage, ArabicImage = DealDto.ArabicImage, DealURL = DealDto.DealURL, DealDescription = DealDto.DealDescription, StartDate = DealDto.StartDate, EndDate = DealDto.EndDate, TimeZone = DealDto.CountryTimezone, Status = 1 }); return("Deal created successfully"); } else { return("Deal is not created, we allow only three active Deals"); } } else if (DealDto.StartDate < Timezone) { return("Please select the start date is greater then present date"); } else { return("Please select the end date is greater then start date."); } }
public DealDto UpdateDeal(DealDto dealDto) { var deal = Mapper.Map <DealDto, Deal>(dealDto); if (dealDto.MenuItems == null || dealDto.MenuItems.Count == 0) { throw new InvalidOperationException("There must be at least one menu item added to the deal to create a new deal."); } var menuItems = dealDto.MenuItems.Select(Mapper.Map <MenuItemDto, MenuItem>).ToList(); var updatedDeal = _dealDataProvider.UpdateDeal(deal, menuItems); var updatedMenuItems = updatedDeal.DealMenuItems.Select(ug => ug.MenuItem).ToList(); var updatedDealDto = Mapper.Map <Deal, DealDto>(updatedDeal); updatedDealDto.MenuItems = updatedMenuItems.Select(Mapper.Map <MenuItem, MenuItemDto>).ToList(); return(updatedDealDto); }
private void deal(ClientPeer client, DealDto dto) { SingleExecute.Instance.Execute(() => { if (!userCache.IsOnline(client)) { return; } int userId = userCache.GetId(client); if (userId != dto.UserId) { return; } FightRoom fightRoom = fightCache.GetRoomByUId(userId); bool canDeal = fightRoom.DeadCard(dto.Type, dto.Weight, dto.Length, dto.UserId, dto.selectCardList); if (canDeal == false) { client.Send(OpCode.FIGHT, FightCode.DEAL_SRES, -1); return; } else { //send deal successful message client.Send(OpCode.FIGHT, FightCode.DEAL_SRES, 0); //check reamin hands List <CardDto> remainCard = fightRoom.GetPlayerModel(userId).CardList; dto.RemainCardList = remainCard; Broadcast(fightRoom, OpCode.FIGHT, FightCode.DEAL_BROADCAST, dto); if (remainCard.Count == 0) { Console.WriteLine("Game Over"); gameOver(userId, fightRoom); } else { Turn(fightRoom); } } }); }
public DealDto AddNewDeal(DealDto dealDto) { var dealToAdd = Mapper.Map <DealDto, Deal>(dealDto); if (dealDto.MenuItems == null || dealDto.MenuItems.Count == 0) { throw new InvalidOperationException("There must be at least one menu item added to the deal to create a new deal."); } var menuItemsToAdd = dealDto.MenuItems.Select(Mapper.Map <MenuItemDto, MenuItem>).ToList(); var newDeal = _dealDataProvider.AddNewDeal(dealToAdd, menuItemsToAdd); var newMenuItems = newDeal.DealMenuItems.Select(dmi => dmi.MenuItem).ToList(); var newDealDto = Mapper.Map <Deal, DealDto>(newDeal); newDealDto.MenuItems = newMenuItems.Select(Mapper.Map <MenuItem, MenuItemDto>).ToList(); return(newDealDto); }
private void btnSave_Click(object sender, RoutedEventArgs e) { if (cbSeeker.SelectedItem == null) { MessageBox.Show("Выберите соискателя", "Проверка"); return; } if (cbPosition.SelectedItem == null) { MessageBox.Show("Выберите вакансию", "Проверка"); return; } if (dpDateOfDeal.DisplayDate == null) { MessageBoxResult result = MessageBox.Show("При указании пустой даты будет указана сегодняшняя дата: " + DateTime.Today.ToShortDateString() + "\nВы уверены?", "Проверка", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result != MessageBoxResult.Yes) { return; } } decimal commission; decimal.TryParse(tbCommissions.Text, out commission); DealDto deal = new DealDto(); deal.DateOfDeal = dpDateOfDeal.SelectedDate.Value.Date; deal.Commission = commission; deal.Position = cbPosition.SelectedItem as PositionDto; deal.Seeker = cbSeeker.SelectedItem as JobSeekerDto; IDealProcess dealProcess = ProcessFactory.GetDealProcess(); if (_dealID == 0) { dealProcess.Add(deal); } else { deal.DealID = _dealID; dealProcess.Update(deal); } Close(); }
public IHttpActionResult UpdateDeal(int id, DealDto dealDto) { if (!ModelState.IsValid) { return(BadRequest()); } var dealInDb = _context.Deals.SingleOrDefault(d => d.DealId == id); if (dealInDb == null) { return(NotFound()); } Mapper.Map(dealDto, dealInDb); _context.SaveChanges(); return(Ok()); }
/// <summary> /// 出牌 出选中的牌 /// </summary> private void dealSelectCard() { List <CardDto> selectCardList = getSelectCard(); DealDto dto = new DealDto(selectCardList, Models.GameModel.Id); //进行合法判断 if (dto.IsRegular == false) { //如果出牌不合法 2 4 promptMsg.Change("请选择合理的手牌!", Color.red); Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, promptMsg); return; } else { //可以出牌 //向服务器发送出牌命令 socketMsg.Change(OpCode.FIGHT, FightCode.DEAL_CREQ, dto); Dispatch(AreaCode.NET, 0, socketMsg); } }
public void Load(DealDto dealDto) { if (dealDto == null) { return; } _dealID = dealDto.DealID; if (dealDto.DateOfDeal.HasValue) { dpDateOfDeal.SelectedDate = dealDto.DateOfDeal.Value; } if (dealDto.Commission.HasValue) { tbCommissions.Text = dealDto.Commission.ToString(); } if (dealDto.Position != null) { foreach (PositionDto positionDto in Positions) { if (dealDto.Position.PositionID == positionDto.PositionID) { this.cbPosition.SelectedItem = positionDto; break; } } } if (dealDto.Seeker != null) { foreach (JobSeekerDto jobSeekerDto in Seekers) { if (dealDto.Seeker.SeekerID == jobSeekerDto.SeekerID) { this.cbSeeker.SelectedItem = jobSeekerDto; break; } } } }
private void dealBroadcast(DealDto dto) { //remove deal cards int userId = dto.UserId; int eventCode = -1; if (dto.UserId == Models.GameModel.MatchRoomDto.LeftId) { eventCode = CharacterEvent.REMOVE_LEFT_CARD; } else if (dto.UserId == Models.GameModel.MatchRoomDto.RightId) { eventCode = CharacterEvent.REMOVE_RIGHT_CARD; } else if (dto.UserId == Models.GameModel.UserDto.Id) { eventCode = CharacterEvent.REMOVE_MY_CARD; } //update current palyer hands Dispatch(AreaCode.CHARACTER, eventCode, dto.RemainCardList); //update ui Dispatch(AreaCode.CHARACTER, CharacterEvent.UPDATE_SHOW_DESK, dto.selectCardList); }