/// <summary> /// Saves place data /// </summary> /// <param name="place">Place object</param> /// <param name="tenantCode">Tenant code (optional)</param> /// <returns>(<see cref="Place"/>) Place object</returns> public static Place SavePlace(Place place, string tenantCode = null) { foreach (var scheduleApp in place.Schedule.ScheduleApps) { if (scheduleApp.ParametersInstance == null) { scheduleApp.ParametersInstance = "{}"; } } place.Updated = DateTime.MaxValue.ToString("yyyy-MM-ddTHH:mm:ss"); var resp = RestController.HttpRequestJson( string.Format(UriCxm.PlacesById, place.Id), Method.POST, place, tenantCode); place = JsonConvert.DeserializeObject <Place>(resp.Content); foreach (var scheduleApp in place.Schedule.ScheduleApps) { scheduleApp.ParametersInstanceJson = JsonConvert.DeserializeObject <ParametersInstance>(scheduleApp.ParametersInstance); } return(place); }
/// <summary> /// Creates a new place iBeacon with or without a child /// </summary> /// <param name="status">Desired place status</param> /// <param name="isAssignIbeacon">Whether iBeacon device should be assigned to the new place(s) (optional)</param> /// <param name="isAddChild">Whether child place should be added or not (optional)</param> /// <returns>(<see cref="Place"/>) New parent place object</returns> public static Place CreateNewPlaceIbeacon( PlaceStatus status, bool isAssignIbeacon = false, bool isAddChild = false) { var bodyObject = new Place { DeviceTypeId = (int)PlaceType.Ibeacon, Id = null, PlaceModules = new List <PlaceModule> { new PlaceModule { ModuleId = (int)PlaceType.Ibeacon, Configuration = JsonConvert.SerializeObject( new Configuration { apps = new List <string>() }) } }, ChildPlaces = new List <ChildPlace>(), DirectItems = new List <DirectItem>(), Title = $"Auto test {ActionManager.RandomNumber}", Schedule = new Schedule { ScheduleApps = new List <ScheduleApp>() }, TimeZoneId = 8, Radius = 5, Status = (int)status }; if (isAssignIbeacon) { var ibeacon = GetIbeacon() ?? CreateIbeacon(); bodyObject.Device = ibeacon; } var response = RestController.HttpRequestJson(string.Format(UriCxm.PlacesById, "null"), Method.POST, bodyObject); var parentPlace = JsonConvert.DeserializeObject <Place>(response.Content); if (isAddChild) { var childPlace = bodyObject; childPlace.Title = $"Auto test {ActionManager.RandomNumber}"; childPlace.ParentId = parentPlace.Id; RestController.HttpRequestJson(string.Format(UriCxm.PlacesById, childPlace.Id), Method.POST, childPlace); } if (status == PlaceStatus.Deleted) { RestController.HttpRequestJson(string.Format(UriCxm.PlacesById, parentPlace.Id), Method.DELETE); } parentPlace = GetById(parentPlace.Id); return(parentPlace); }
/// <summary> /// Deletes place and its children /// </summary> /// <param name="place">Place object</param> public static Place DeletePlace(Place place) { var resp = RestController.HttpRequestJson( string.Format(UriCxm.PlacesDelete, place.Id, "true"), Method.DELETE); return(JsonConvert.DeserializeObject <Place>(resp.Content)); }
/// <summary> /// Creates a new place with empty Device Type /// </summary> /// <param name="isAddChild">Whether child place should assigned to the created place (optional)</param> /// <returns>(<see cref="Place"/>) New parent place object</returns> public static Place CreateNewPlaceNoType(bool isAddChild) { var bodyObject = new Place { DeviceTypeId = null, Id = null, PlaceModules = new List <PlaceModule> { new PlaceModule { ModuleId = 2, Configuration = JsonConvert.SerializeObject( new Configuration { apps = new List <string> () }) } }, ChildPlaces = new List <ChildPlace>(), DirectItems = new List <DirectItem>(), Title = $"Auto test {ActionManager.RandomNumber}", Schedule = new Schedule { ScheduleApps = new List <ScheduleApp>() }, TimeZoneId = 8, Radius = 5, Status = (int)PlaceStatus.NoDevice }; var response = RestController.HttpRequestJson(string.Format(UriCxm.PlacesById, "null"), Method.POST, bodyObject); var parent = JsonConvert.DeserializeObject <Place>(response.Content); if (isAddChild) { var child = bodyObject; bodyObject.Title = $"Auto test {ActionManager.RandomNumber}"; child.ParentId = parent.Id; RestController.HttpRequestJson(string.Format(UriCxm.PlacesById, "null"), Method.POST, child); } parent = GetById(parent.Id); return(parent); }