public void AddPlayer(Person player) { if (player.Age < 40) { FirstTeam.Add(player); } else { ReserveTeam.Add(player); } }
public async Task <IActionResult> Create(ReserveAPI item) { if (item == null) { return(BadRequest()); } if (item.Participants.Contains(User.Identity.Name)) { return(BadRequest("Нельзя добавлять себя в участников!")); } var participants = await _appContext.Users.Where(x => item.Participants.Contains(x.Email)).ToListAsync(); double dHours = item.EndDate.Hour - item.StartDate.Hour; dHours += (item.EndDate.Minute - item.StartDate.Minute) / 60.0; var user = await _appContext.Users.SingleOrDefaultAsync(x => x.Email == User.Identity.Name); var reserve = new Reserve { DateTime = item.StartDate, Hours = dHours, RoomId = item.RoomId, UserId = user.Id }; var checkReserves = _appContext.Reserve.Where(x => x.DateTime.Date == item.StartDate.Date && ((x.DateTime > item.StartDate && x.DateTime < item.EndDate) || (x.DateTime.AddHours(x.Hours) > item.StartDate && x.DateTime.AddHours(x.Hours) < item.EndDate))); if (checkReserves.Count() != 0) { return(BadRequest("Заказ пересекается с другим заказом по времени!")); } var devList = await _appContext.Device.Where(x => item.Devices.Contains(x.Id)).ToListAsync(); devList.ForEach(x => x.RoomId = item.RoomId); await _appContext.Reserve.AddAsync(reserve); var reserveTeam = new ReserveTeam { ReserveId = reserve.Id }; await _appContext.ReserveTeam.AddAsync(reserveTeam); participants.ForEach(x => x.ReserveTeamUser.Add(new ReserveTeamUser { ReserveTeamId = reserveTeam.Id, UserId = x.Id })); await _appContext.SaveChangesAsync(); return(Ok(reserve)); }