public IActionResult UpdateEvent([FromBody] UpdateEventModel InputModel) { // Fetch Tenant ID from Bearer Token var tenant_id = @User.Claims.FirstOrDefault(c => c.Type == "tenant_id").Value; if (tenant_id == null) { return(Unauthorized()); } // Event end date should not be less than start date if (InputModel.Event_End_Date != null) { if (InputModel.Event_End_Date < InputModel.Event_Start_Date) { return(BadRequest("End date can not be smaller than start date.")); } } // Map values with event model Event objEvent = new Event(); objEvent._id = InputModel._id; objEvent.Event_Name = InputModel.Event_Name; objEvent.Event_Description = InputModel.Event_Description; objEvent.Event_Venue = InputModel.Event_Venue; objEvent.Event_Owner = tenant_id; objEvent.Event_Start_Date = InputModel.Event_Start_Date; objEvent.Event_End_Date = InputModel.Event_End_Date; return(Ok(_eventsService.UpdateEvent(objEvent))); }
public async Task <ActionResult> UpdateEventAsync(Guid id, UpdateEventModel updateEventModel) { if (id != updateEventModel.Id) { return(BadRequest()); } var evnt = await _eventService.GetEventAsync(id); if (evnt is null) { return(NotFound()); } var eventModel = new EventModel { Id = id, Title = updateEventModel.Title, Description = updateEventModel.Description, StartDate = updateEventModel.StartDate, EndDate = updateEventModel.EndDate, AllDay = updateEventModel.AllDay, Place = updateEventModel.Place }; var updatedEvent = await _eventService.UpdateEventAsync(eventModel); return(NoContent()); }
public async Task <bool> UpdateEventAsync(Guid eventId, UpdateEventModel entity) { var updatingEvent = await _repository.GetEventAsync(eventId); _mapper.Map(entity, updatingEvent); return(await _repository.UpdateEventAsync(updatingEvent)); }
public async Task <ActionResult <GetEventModel> > UpdateEvent(UpdateEventModel request) { var validationResult = _eventValidation.ValidateUpdateEvent(request); if (!validationResult.ValidationResult) { return(BadRequest(validationResult.ValidationMessage)); } return(await _eventLogic.UpdateEvent(request)); }
public (bool ValidationResult, string ValidationMessage) ValidateUpdateEvent(UpdateEventModel model) { if (!_eventRepository.CheckEventExistence(model.EventUid).Result) { return(false, ErrorDictionary.GetErrorMessage(10, _culture)); } if (model.Status.HasValue && !Enum.IsDefined(typeof(EventStatus), model.Status)) { return(false, ErrorDictionary.GetErrorMessage(13, _culture)); } if (model.Types != null) { if (model.Types.Count != model.Types.Distinct().Count()) { return(false, ErrorDictionary.GetErrorMessage(37, _culture)); } if (model.Types.Count > 3) { return(false, ErrorDictionary.GetErrorMessage(35, _culture)); } foreach (var type in model.Types) { if (!Enum.IsDefined(typeof(EventType), type)) { return(false, ErrorDictionary.GetErrorMessage(14, _culture)); } } } if (model.MinAge.HasValue && model.MaxAge.HasValue && model.MinAge > model.MaxAge) { return(false, ErrorDictionary.GetErrorMessage(15, _culture)); } if (model.StartTime.HasValue && model.EndTime.HasValue && model.StartTime > model.EndTime) { return(false, ErrorDictionary.GetErrorMessage(42, _culture)); } if (model.CityId.HasValue) { var cities = _cityLogic.GetCities().Result; if (!cities.Any(x => x.CityId == model.CityId)) { return(false, ErrorDictionary.GetErrorMessage(30, _culture)); } } if (model.PrimaryImage != null && model.PrimaryImage.Any()) { var eventModel = _eventRepository.GetEvent(model.EventUid).Result; if (eventModel.EventImageContentEntities.Any(x => x.IsPrimary.HasValue && x.IsPrimary.Value)) { return(false, ErrorDictionary.GetErrorMessage(46, _culture)); } } return(true, string.Empty); }
/// <summary> /// This method handles all the updates from the API. /// </summary> /// <param name="updateEventModel"></param> private void HandleApiUpdate(UpdateEventModel updateEventModel) { try { // Check if the layer values are updated and if so update them in the GameModel if (updateEventModel.UpdatedLayerValues != null) { UpdateLayerValues(updateEventModel.UpdatedLayerValues); } // Check if a neighbourhood is removed if (updateEventModel.RemovedNeighbourhood != null) { RemoveNeighbourhood(updateEventModel.RemovedNeighbourhood); } // Check if a visualized object is removed. For now it is probably a building if (updateEventModel.RemovedVisualizedObject != null) { // Removed visualized object is just an identifier RemoveVisualizedBuildings(updateEventModel.NeighbourhoodName, updateEventModel.RemovedVisualizedObject); } // Check if a neighbourhood is updated if (updateEventModel.UpdatedNeighbourhood != null) { // Update age & LayerValues UpdateNeighbourhood(updateEventModel.NeighbourhoodName, updateEventModel.UpdatedNeighbourhood); } if (updateEventModel.AddedNeighbourhood != null) { AddNeighbourhood(updateEventModel.AddedNeighbourhood); } if (updateEventModel.AddedVisualizedObject != null) { AddBuilding(updateEventModel.NeighbourhoodName, updateEventModel.AddedVisualizedObject); } CityUpdatedEvent?.Invoke(); } catch (Exception e) { #if UNITY_EDITOR Debug.LogError(e.StackTrace); #else Debug.LogError(e.Message); #endif } }
/// <summary> /// This function will check if vehicles needs to be marked as destroyed or if we need to spawn new vehicles. /// </summary> /// <param name="updateEventModel"></param> private void UpdateEvent(UpdateEventModel updateEventModel) { if (updateEventModel.UpdatedVisualizedObjects == null) { return; } // Select all vehicles that we currently have. List <VisualizedVehicleModel> oldVehicles = Vehicles.Select(x => x.VehicleModel).ToList(); // Select all the new vehicles we got from the API. List <VisualizedVehicleModel> newVehicles = updateEventModel.UpdatedVisualizedObjects.OfType <VisualizedVehicleModel>().ToList(); // Make a list of all the vehicles that are not in the new batch of vehicles. List <VisualizedVehicleModel> removedVehicles = oldVehicles.Except(newVehicles).ToList(); // Make a list of newly added vehicles. List <VisualizedVehicleModel> addedVehicles = newVehicles.Except(oldVehicles).Where(v => v.Size > 0).ToList(); // Remove all the old vehicles and mark them to destroy. foreach (VisualizedVehicleModel removedVehicle in removedVehicles) { Vehicle v = Vehicles.Single(x => x.VehicleModel.Equals(removedVehicle)); if (v.NeighbourhoodModel.VisualizedObjects.Contains(v.VehicleModel)) { v.NeighbourhoodModel.VisualizedObjects.Remove(v.VehicleModel); } if (CameraController.Instance.FollowTargetObject == v.VehicleGameObject) { CameraController.Instance.StopFollowingTarget(); } Destroy(v.VehicleGameObject); Vehicles.Remove(v); } // Spawn all the new vehicles in a random order. foreach (VisualizedVehicleModel addedVehicle in addedVehicles) { SpawnVehicle(addedVehicle); } TrafficUpdateEvent.Invoke(); }
/// <summary> /// Try to start the SignalR connection with the server. /// </summary> private void StartSignalR() { if (string.IsNullOrEmpty(SettingsManager.Instance.Settings.Api.EventHubEndpoint)) { Debug.LogWarning("SignalR is not enabled, no endpoint is set. Real-time data is unavailable."); return; } _srLib = new SignalRLib(); _srLib.Init(_hubEndpoint, HubListenerName); _srLib.Error += (sender, e) => { _alertText.text = $"Error retrieving live data from server! Server seems to be down."; AlertCanvas.SetActive(true); #if UNITY_EDITOR Debug.LogError($"SignalR gives an error: {e.Message}"); #endif }; _srLib.ConnectionStarted += (sender, e) => { Debug.Log("Connection with server established."); }; _srLib.MessageReceived += (sender, e) => { // Disable alerting text if server went back up if (_alertText.gameObject.activeSelf) { _alertText.gameObject.SetActive(false); } UpdateEventModel updateEventModel = JsonParser.ParseUpdateEvent(e.Message); if (Application.isEditor && updateEventModel.UpdatedLayerValues == null) { Debug.Log(e.Message); } ApiUpdateEvent?.Invoke(updateEventModel); }; }
public void UpdateEvent(UpdateEventModel model) { var context = DataEntitiesProvider.Provide(); var evt = context.Events.SingleOrDefault(x => x.EIN == model.EventId); if (evt == null) { throw new ArgumentOutOfRangeException("Event ID " + model.EventId + " not recognised"); } // TODO - valiudate // Calculate ranks and pentamind points var rankCalculator = RankCalculatorFactory.Get(evt); if (rankCalculator.CanCalculate(model.Entrants)) { // TODO high-score-is-best rankCalculator.Calculate(evt.Number_in_Team, true, model.Entrants); // TODO some nasty hard coding for 2020 - also these big events can't be done via the desktop int overridingNumberOfEntrants = 0; /* if (evt.OlympiadId == 25 && evt.Code == "POTH") overridingNumberOfEntrants = 1049; * if (evt.OlympiadId == 25 && evt.Code == "POOM") overridingNumberOfEntrants = 499; * if (evt.OlympiadId == 25 && evt.Code == "PO7S") overridingNumberOfEntrants = 339; * if (evt.OlympiadId == 25 && evt.Code == "POHU") overridingNumberOfEntrants = 704; * if (evt.OlympiadId == 25 && evt.Code == "PO5D") overridingNumberOfEntrants = 258; * if (evt.OlympiadId == 25 && evt.Code == "POOH") overridingNumberOfEntrants = 332; * if (evt.OlympiadId == 25 && evt.Code == "POH6") overridingNumberOfEntrants = 380; * if (evt.OlympiadId == 25 && evt.Code == "PZKK") overridingNumberOfEntrants = 380; */ var pentaCalculator = new Penta2021Calculator(); pentaCalculator.Calculate(evt.Number_in_Team, model.Entrants, evt.Pentamind, evt.PentamindFactor, overridingNumberOfEntrants); } // TODO - events with partners // Do the saving - see EventPanel. We'remissing bits such as the EventIndexer if only updating results // Event properties // Entrants // Entrants are *not* added here but their ranks etc are foreach (var e in model.Entrants) { var entrant = context.Entrants.First(x => x.EntryNumber == e.EntryNumber); entrant.Absent = e.Absent; entrant.Medal = (string.IsNullOrEmpty(e.Medal)) ? null : e.Medal; entrant.JuniorMedal = (string.IsNullOrEmpty(e.JuniorMedal)) ? null : e.JuniorMedal; entrant.Rank = e.Rank; entrant.Score = (string.IsNullOrWhiteSpace(e.Score)) ? null : e.Score; if (e.Rank > 0) { entrant.Penta_Score = e.PentaScore; } else { entrant.Penta_Score = null; } // zero length constraint entrant.Tie_break = (e.Tiebreak == "") ? null : e.Tiebreak; // TODO entrant.Partner = e.TeamOrPair; } context.SaveChanges(); }
public async Task <GetEventModel> UpdateEvent(UpdateEventModel updateEventModel) { var eventEntity = await _eventRepository.GetEvent(updateEventModel.EventUid); if (!string.IsNullOrEmpty(updateEventModel.Name)) { eventEntity.Name = updateEventModel.Name; } if (updateEventModel.MinAge.HasValue) { eventEntity.MinAge = updateEventModel.MinAge; } if (updateEventModel.MaxAge.HasValue) { eventEntity.MaxAge = updateEventModel.MaxAge; } if (updateEventModel.XCoordinate.HasValue) { eventEntity.XCoordinate = updateEventModel.XCoordinate.Value; } if (updateEventModel.YCoordinate.HasValue) { eventEntity.YCoordinate = updateEventModel.YCoordinate.Value; } if (!string.IsNullOrEmpty(updateEventModel.Description)) { eventEntity.Description = updateEventModel.Description; } if (updateEventModel.StartTime.HasValue) { eventEntity.StartTime = updateEventModel.StartTime; } if (updateEventModel.EndTime.HasValue) { eventEntity.EndTime = updateEventModel.EndTime; } if (updateEventModel.IsOpenForInvitations.HasValue) { eventEntity.IsOpenForInvitations = updateEventModel.IsOpenForInvitations; } if (updateEventModel.IsOnline.HasValue) { eventEntity.IsOnline = updateEventModel.IsOnline; } if (updateEventModel.CityId.HasValue) { eventEntity.CityId = updateEventModel.CityId; } var images = new List <EventImageContentEntity>(); if (updateEventModel.ExtraImages != null && updateEventModel.ExtraImages.Any()) { foreach (var image in updateEventModel.ExtraImages) { var eventImageContentUid = await _imageLogic.SaveImage(image); images.Add(new EventImageContentEntity { EventImageContentUid = eventImageContentUid, IsPrimary = false }); } eventEntity.EventImageContentEntities = images; } if (updateEventModel.PrimaryImage != null && updateEventModel.PrimaryImage.Any()) { var eventImageContentUid = await _imageLogic.SaveImage(updateEventModel.PrimaryImage); images.Add(new EventImageContentEntity { EventImageContentUid = eventImageContentUid, IsPrimary = true }); } eventEntity.EventImageContentEntities = images; if (updateEventModel.Types != null && updateEventModel.Types.Any()) { await _eventRepository.RemoveEventTypes(eventEntity.EventId); eventEntity.EventTypes = new List <EventTypeToEventEntity>( updateEventModel.Types.Select(x => new EventTypeToEventEntity { EventId = eventEntity.EventId, EventTypeId = (long)x })); } else { eventEntity.EventTypes = null; } if (updateEventModel.Status.HasValue) { eventEntity.EventStatusId = (long)updateEventModel.Status; } eventEntity.EventStatus = null; eventEntity.City = null; eventEntity.Administrator = null; eventEntity.Participants = null; eventEntity.Chat = null; eventEntity.SwipeHistory = null; await _eventRepository.UpdateEvent(eventEntity); return(await GetEvent(eventEntity.EventUid)); }
/// <summary> /// Function to parse an update event into the correct model. /// If API structure changes happen it should be adjusted in here. /// </summary> /// <param name="jsonString"></param> /// <returns></returns> public static UpdateEventModel ParseUpdateEvent(string jsonString) { JSONNode jsonOBj = JSON.Parse(jsonString); UpdateEventModel updateEventModel = new UpdateEventModel(); if (jsonOBj["neighbourhoodName"] != null) { updateEventModel.NeighbourhoodName = jsonOBj["neighbourhoodName"]; } if (jsonOBj["removedNeighbourhood"] != null) { updateEventModel.RemovedNeighbourhood = jsonOBj["removedNeighbourhood"]; } if (jsonOBj["addedNeighbourhood"] != null) { updateEventModel.AddedNeighbourhood = ParseNeighbourhoodModel(jsonOBj["addedNeighbourhood"]); } if (jsonOBj["updatedNeighbourhood"] != null) { updateEventModel.UpdatedNeighbourhood = ParseNeighbourhoodModel(jsonOBj["updatedNeighbourhood"]); } if (jsonOBj["removedVisualizedObject"] != null) { updateEventModel.RemovedVisualizedObject = jsonOBj["removedVisualizedObject"]; } if (jsonOBj["addedVisualizedObject"] != null) { updateEventModel.AddedVisualizedObject = VisualizedObjectFactory.Build( jsonOBj["addedVisualizedObject"]["type"], jsonOBj["addedVisualizedObject"]["size"], null, jsonOBj["addedVisualizedObject"]["identifier"]); } if (jsonOBj["updatedVisualizedObjects"] != null) { List <IVisualizedObject> visualizedObjects = new List <IVisualizedObject>(); foreach (JSONNode updatedVisualizedObjectNode in jsonOBj["updatedVisualizedObjects"].Children) { visualizedObjects.Add(VisualizedObjectFactory.Build( updatedVisualizedObjectNode["type"], updatedVisualizedObjectNode["size"], null, updatedVisualizedObjectNode["identifier"])); } if (visualizedObjects.Count > 0) { updateEventModel.UpdatedVisualizedObjects = visualizedObjects; } } if (jsonOBj["updatedLayerValues"] != null) { Dictionary <string, Dictionary <string, double> > updatedLayerValues = new Dictionary <string, Dictionary <string, double> >(); foreach (KeyValuePair <string, JSONNode> layerValue in jsonOBj["updatedLayerValues"]) { Dictionary <string, double> layerValues = new Dictionary <string, double>(); foreach (KeyValuePair <string, JSONNode> values in layerValue.Value) { layerValues.Add(values.Key, values.Value); } updatedLayerValues.Add(layerValue.Key, layerValues); } updateEventModel.UpdatedLayerValues = updatedLayerValues; } return(updateEventModel); }