public async Task Update(ClientsGroupsBll elementToUpdate) { ClientsGroups clientsGroups = Mapper.Map <ClientsGroupsBll, ClientsGroups>(elementToUpdate); _unitOfWork.ClientsGroupsUnitOfWork.Update(clientsGroups); await _unitOfWork.Save(); }
/// <summary> /// Валидация /// </summary> /// <param name="clientsGroups"></param> private void CheckClientGroup(ClientsGroups clientsGroups) { if (clientsGroups?.Size < 1 && clientsGroups?.Size > 6) { throw new Exception("Количество гостей от 1 до 6"); } }
public async Task Insert(ClientsGroupsBll element) { ClientsGroups clientsGroups = Mapper.Map <ClientsGroupsBll, ClientsGroups>(element); _unitOfWork.ClientsGroupsUnitOfWork.Insert(clientsGroups); await _unitOfWork.Save(); }
/// <summary> /// Убытие клиента /// </summary> private void Leave(ClientsGroups clientsGroups) { var table = this.tables .FirstOrDefault(x => x.Value.Any(a => a.Guid == clientsGroups.Guid)) .Key; if (table != null) { this.tables[table].RemoveAll(x => x.Guid == clientsGroups.Guid); } var freeSize = table.Size - this.tables[table].Sum(x => x.Size); var tempFreeSize = freeSize; // будем искать людей в очереди, кто пришел раньше // начнем с тех, кого меньше for (int i = 1; i <= freeSize; i++) { var nextClients = this.clients.Where(x => x.Size == i).ToList(); foreach (var nextClient in nextClients) { // уберем из очереди this.clients.Remove(nextClient); // добавим к столу this.tables[table].Add(nextClient); // если свободного места не осталось, завершим перебор if (freeSize < 1) { break; } freeSize -= i; } } this.Bored(freeSize); }
/// <summary> /// Прибытие клиента /// </summary> /// <param name="clientsGroups"></param> private void Arrive(ClientsGroups clientsGroups) { // сначала пытаемся найти свободный стол нужного размера var freeTable = this.tables .Where(x => !x.Value.Any() && x.Key.Size == clientsGroups.Size) .FirstOrDefault() .Key; // .. ищем размера побольше if (freeTable == null) { freeTable = this.tables .Where(x => !x.Value.Any() && x.Key.Size > clientsGroups.Size) .FirstOrDefault() .Key; } // .. ищем занятый if (freeTable == null) { freeTable = this.tables .Where(x => (x.Key.Size - x.Value.Sum(s => s.Size)) >= clientsGroups.Size) .FirstOrDefault() .Key; } var freeSize = freeTable.Size - this.tables[freeTable].Sum(x => x.Size); if (freeTable == null) { this.clients.Add(clientsGroups); return; } this.tables[freeTable].Add(clientsGroups); this.Bored(freeSize); }
public void OnLeave(ClientsGroups clientsGroups) { throw new NotImplementedException(); }
public Table Lookup(ClientsGroups clientsGroups) { throw new NotImplementedException(); }
/// <summary> /// Убытие клиента /// </summary> /// <param name="clientsGroups"></param> public void OnLeave(ClientsGroups clientsGroups) { this.messages.Enqueue(new Message(ActionType.Leave, clientsGroups)); }
/// <summary> /// Посмотреть столик клиента /// </summary> /// <param name="clientsGroups"></param> /// <returns></returns> public Table Lookup(ClientsGroups clientsGroups) { return(this.tables.FirstOrDefault(x => x.Value.Any(a => a.Guid == clientsGroups.Guid)).Key); }
public Message(ActionType type, ClientsGroups clientsGroups) { this.Type = type; this.ClientsGroups = clientsGroups; }
public Table LookupAll([FromQuery] ClientsGroups clientsGroups) { this.CheckClientGroup(clientsGroups); return(this.restManager.Lookup(clientsGroups)); }
public void OnLeave([FromBody] ClientsGroups clientsGroups) { this.CheckClientGroup(clientsGroups); this.restManager.OnLeave(clientsGroups); }