public IHttpActionResult Add(NetworkModel networkModel) { if (networkModel == null) { var errorMessage = _messages.GetMessage(Generic.NullObject); return(BadRequest(errorMessage)); } if (_networkRep.GetAll() .Any(p => p.Name == networkModel.Name)) { var errorMessage = _messages.GetMessage(Custom.Conflict, "Network", "Name"); return(Conflict(errorMessage)); } _credentials.SetCredentials(Request.Headers.Authorization.Parameter); var userId = _userRep.Get(_credentials.Email, _credentials.Password).Id; var newNetwork = _mapper.Map <Network>(networkModel); newNetwork.User_Id = userId; newNetwork.Address = _guid.GetAddress(); newNetwork.ProductionDate = _dateTime.GetDateTime(); _networkRep.Add(newNetwork); var createdNetwork = _mapper.Map <NetworkModelGet>(newNetwork); return(CreatedAtRoute("GetNetwork", new { id = createdNetwork.Id }, createdNetwork)); }
public async Task <(bool hasReport, object report, string message)> PreProcessingSalesPunctuation(FilterDto filterDto) { var sales = await _saleRepository.CustomFind(x => !x.Activated && !x.Processed && x.CurrentMonth == filterDto.CurrentMonth && x.CurrentYear == filterDto.CurrentYear, x => x.Network); if (!sales.Any()) { return(false, null, "Nenhum registro encontrado no parametro informado"); } var networks = await _networkRepository.GetAll(); networks = networks.OrderBy(x => x.Name); var report = networks.Select(x => new { Network = x.Name, Salesman = sales.Where(s => s.Network.Id == x.Id).Sum(s => s.Punctuation), RegionManager = sales.Where(s => s.Network.Id == x.Id).Sum(s => s.Punctuation) * (decimal)0.05, Manager = sales.Where(s => s.Network.Id == x.Id).Sum(s => s.Punctuation) * (decimal)0.1, Total = sales.Where(s => s.Network.Id == x.Id).Sum(s => s.Punctuation) + (sales.Where(s => s.Network.Id == x.Id).Sum(s => s.Punctuation) * (decimal)0.05) + (sales.Where(s => s.Network.Id == x.Id).Sum(s => s.Punctuation) * (decimal)0.1) }).ToList(); return(true, report, "Relatório gerado com sucesso"); }
public IHttpActionResult GetGatewayConnections(int networkId, int gatewayId, int page = 1, int pageSize = 30) { _credentials.SetCredentials(Request.Headers.Authorization.Parameter); var userId = _userRep.Get(_credentials.Email, _credentials.Password).Id; if (!_networkRep.GetAll().Any(n => n.Id == networkId && n.User_Id == userId)) { var errorMessage = _messages.GetMessage(Custom.NotFound, "Network", "Id"); return(NotFound(errorMessage)); } var gateway = _gatewayRep.Get(gatewayId); if (gateway == null) { var errorMessage = _messages.GetMessage(Custom.NotFound, "Gateway", "Id"); return(NotFound(errorMessage)); } if (page < 1) { page = 1; } if (pageSize < 1) { pageSize = 30; } var totalCount = gateway.Connections.Count(); var pageCount = (int)Math.Ceiling((float)totalCount / pageSize); var results = _sensorRep.GetAll() .Join(gateway.Connections, s => s.Id, c => c.Sensor_Id, (s, c) => s) .Skip(pageSize * (page - 1)) .Take(pageSize) .Select(p => _mapper.Map <SensorModelGet>(p)) .ToList(); return(Ok("GetGatewayConnections", page, pageSize, pageCount, totalCount, results)); }
public IHttpActionResult Add(int networkId, SensorModelPost sensorModel) { _credentials.SetCredentials(Request.Headers.Authorization.Parameter); var userId = _userRep.Get(_credentials.Email, _credentials.Password).Id; if (!_networkRep.GetAll().Any(n => n.Id == networkId && n.User_Id == userId)) { var errorMessage = _messages.GetMessage(Custom.NotFound, "Network", "Id"); return(NotFound(errorMessage)); } if (sensorModel == null) { var errorMessage = _messages.GetMessage(Generic.NullObject); return(BadRequest(errorMessage)); } if (!_typeRep.Exists(sensorModel.SensorTypeId)) { var errorMessage = _messages.GetMessage(Custom.NotFound, "Sensor Type", "Id"); return(NotFound(errorMessage)); } if (_sensorRep.GetAll() .Any(p => p.Address == sensorModel.Address)) { var errorMessage = _messages.GetMessage(Custom.Conflict, "Sensor", "Address"); return(Conflict(errorMessage)); } if (_sensorRep.GetAll() .Any(p => p.Name == sensorModel.Name)) { var errorMessage = _messages.GetMessage(Custom.Conflict, "Sensor", "Name"); return(Conflict(errorMessage)); } _credentials.SetCredentials(Request.Headers.Authorization.Parameter); var sensor = _mapper.Map <Sensor>(sensorModel); sensor.ProductionDate = _dateTime.GetDateTime(); sensor.Network_Id = networkId; _sensorRep.Add(sensor); var createdSensor = _mapper.Map <SensorModelGet>(sensor); return(CreatedAtRoute("GetSensor", new { id = createdSensor.Id }, createdSensor)); }
public IHttpActionResult Get(int networkId, int sensorId, int page = 1, int pageSize = 30) { _credentials.SetCredentials(Request.Headers.Authorization.Parameter); var userId = _userRep.Get(_credentials.Email, _credentials.Password).Id; if (!_networkRep.GetAll().Any(n => n.Id == networkId && n.User_Id == userId)) { var errorMessage = _messages.GetMessage(Custom.NotFound, "Network", "Id"); return(NotFound(errorMessage)); } var sensor = _sensorRep.Get(sensorId); if (sensor == null) { var errorMessage = _messages.GetMessage(Custom.NotFound, "Sensor", "Id"); return(NotFound(errorMessage)); } if (page < 1) { page = 1; } if (pageSize < 1) { pageSize = 30; } //This needs to go!!!! var sensorReadings = sensor.SensorType.Name.ToLower() != "vibration" ? _readingRep.Get(sensor.Id) : _readingRep.Get(sensor.Id).Where(r => _vibrationFilter.ValidValues().Contains((int)r.Value)); var totalCount = sensorReadings.Count(); var pageCount = (int)Math.Ceiling((float)totalCount / pageSize); var results = sensorReadings.OrderByDescending(r => r.InsertDate) .Skip(pageSize * (page - 1)) .Take(pageSize) .Select(p => _mapper.Map <SensorReadingModelGet>(p)) .ToList(); return(Ok("GetSensorReadings", page, pageSize, pageCount, totalCount, results)); }
public IEnumerable <string> FindStrongestTeam(string skill, int size) { if (size == 0) { throw new ArgumentException("Team size must be greater than zero"); } var validProgrammers = _networkRepository .GetAll() .Where(programmer => programmer.HasSkill(skill)) .Select(programmer => programmer.GetId()); var possibleTeams = _permutationService.GetPermutations(validProgrammers, size); return(possibleTeams .OrderByDescending(possibleTeam => _teamStrengthService.GetTeamStrength(skill, possibleTeam)) .First() .OrderByDescending(teamMember => _teamStrengthService.GetIndividualStrength(skill, teamMember))); }
public int GetDegreesBetween(string id, string goalId) { if (id == goalId) { return(0); } var goalProgrammer = _programmers.GetById(goalId); _queue.Enqueue(new Node(id, 1)); while (_queue.Count > 0) { var currentNode = _queue.Dequeue(); _visited.Add(currentNode.Id); var currentProgrammer = _programmers.GetById(currentNode.Id); if (AreDirectlyRelated(currentProgrammer, goalProgrammer)) { return(currentNode.Depth); } var recommenders = currentProgrammer.GetRecommenders(_programmers.GetAll()).Select(p => p.GetId()); var neighbours = currentProgrammer .GetRecommendations() .Concat(recommenders); foreach (var neighbour in neighbours) { if (!_visited.Contains(neighbour)) { _queue.Enqueue(new Node(neighbour, currentNode.Depth + 1)); } } } return(0); }
public IHttpActionResult Add(int networkId, GatewayModelPost gatewayModel) { _credentials.SetCredentials(Request.Headers.Authorization.Parameter); var userId = _userRep.Get(_credentials.Email, _credentials.Password).Id; if (!_networkRep.GetAll().Any(n => n.Id == networkId && n.User_Id == userId)) { var errorMessage = _messages.GetMessage(Custom.NotFound, "Network", "Id"); return(NotFound(errorMessage)); } if (gatewayModel == null) { var errorMessage = _messages.GetMessage(Generic.NullObject); return(BadRequest(errorMessage)); } if (_gatewayRep.GetAll().Any(g => g.Name == gatewayModel.Name)) { var errorMessage = _messages.GetMessage(Custom.Conflict, "Gateway", "Name"); return(Conflict(errorMessage)); } if (_gatewayRep.GetAll().Any(g => g.Address == gatewayModel.Address)) { var errorMessage = _messages.GetMessage(Custom.Conflict, "Gateway", "Address"); return(Conflict(errorMessage)); } var newGateway = _mapper.Map <Gateway>(gatewayModel); newGateway.Network_Id = networkId; newGateway.ProductionDate = _dateTime.GetDateTime(); _gatewayRep.Add(newGateway); var createdGateway = _mapper.Map <GatewayModelGet>(newGateway); return(CreatedAtRoute("GetGateway", new { networkId, id = createdGateway.Id }, createdGateway)); }
public RankService(INetworkRepository networkRepository) { _networkRepository = networkRepository; _programmers = _networkRepository.GetAll().ToList(); }