public IHttpActionResult PutCongestion(CongestionModel congestionModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var congestionsExist = db.Congestions.FirstOrDefault(w => w.Id == congestionModel.Id); if (congestionsExist != null) { congestionsExist.Location = Common.CreatePoint(congestionModel.Latitude, congestionModel.Longitude); congestionsExist.Description = congestionModel.Description; congestionsExist.Name = congestionModel.Name; db.SaveChanges(); Common.Push(congestionModel.Longitude, congestionModel.Latitude, 10000, "Traffic jam near Jayamahal due to " + congestionModel.Name, congestionsExist.Id, 1); } else { var congestion = new Congestion(); congestion.Id = Guid.NewGuid(); congestion.IsActive = true; congestion.CongestionTypeId = Guid.Parse("108853b3-4cf0-4141-91d7-5b791e2981dc"); congestion.CreatedDate = DateTime.UtcNow; congestion.Location = Common.CreatePoint(congestionModel.Latitude, congestionModel.Longitude); congestion.Description = congestionModel.Description; congestion.Name = congestionModel.Name; congestion.OrgUserId = Guid.Parse("111faecf-3e24-4e15-9a96-aa924855205b"); congestion.Contact = congestionModel.Contact; db.Congestions.Add(congestion); db.SaveChanges(); Common.Push(congestionModel.Longitude, congestionModel.Latitude, 10000, "Traffic jam near Jayamahal due to " + congestionModel.Name, congestion.Id, 1); } db.SaveChanges(); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public bool UpdateCongestion(string name, float volume) { if (!m_congestions.TryGetValue(name, out Congestion value)) { value = new Congestion(); m_congestions.Add(name, value); } double realTime = Time.RealTime; double lastUpdateTime = value.LastUpdateTime; double lastPlayedTime = value.LastPlayedTime; float num = (lastUpdateTime > 0.0) ? ((float)(realTime - lastUpdateTime)) : 0f; value.Value = MathUtils.Max(value.Value - 10f * num, 0f); value.LastUpdateTime = realTime; if (value.Value <= 6f && (lastPlayedTime == 0.0 || volume > value.LastPlayedVolume || realTime - lastPlayedTime >= 0.0)) { value.LastPlayedTime = realTime; value.LastPlayedVolume = volume; value.Value += 1f; return(true); } return(false); }