/// <summary> /// Delete data collector. /// </summary> /// <param name="request"></param> /// <returns></returns> public GXDataCollectorDeleteResponse Post(GXDataCollectorDeleteRequest request) { IAuthSession s = this.GetSession(false); long id = 0; List <GXAmiDataCollector> list = new List <GXAmiDataCollector>(); List <GXEventsItem> events = new List <GXEventsItem>(); lock (Db) { if (!long.TryParse(s.Id, out id)) { throw new ArgumentException("Access denied."); } //Normal user can't change add new data collectors. if (!GuruxAMI.Server.GXBasicAuthProvider.CanEditDevice(s)) { throw new ArgumentException("Access denied."); } bool superAdmin = GuruxAMI.Server.GXBasicAuthProvider.IsSuperAdmin(s); if (request.DataCollectorIDs != null) { //TODO: check that user can't remove DC that he do not have access. foreach (ulong it in request.DataCollectorIDs) { List <GXAmiDataCollector> item = Db.Select <GXAmiDataCollector>(q => q.Id == it); if (request.Permanently) { Db.Delete(item[0]); } else { if (item.Count != 1) { throw new ArgumentException("Access denied."); } else { item[0].Removed = DateTime.Now.ToUniversalTime(); Db.UpdateOnly(item[0], p => p.Removed, p => p.Id == it); } } events.Add(new GXEventsItem(ActionTargets.DataCollector, Actions.Remove, item[0])); } } } AppHost host = this.ResolveService <AppHost>(); host.SetEvents(Db, this.Request, id, events); return(new GXDataCollectorDeleteResponse()); }
/// <summary> /// Delete data collector. /// </summary> /// <param name="request"></param> /// <returns></returns> public GXDataCollectorDeleteResponse Post(GXDataCollectorDeleteRequest request) { IAuthSession s = this.GetSession(false); long id = 0; List<GXAmiDataCollector> list = new List<GXAmiDataCollector>(); List<GXEventsItem> events = new List<GXEventsItem>(); lock (Db) { if (!long.TryParse(s.Id, out id)) { throw new ArgumentException("Access denied."); } //Normal user can't change add new data collectors. if (!GuruxAMI.Server.GXBasicAuthProvider.CanEditDevice(s)) { throw new ArgumentException("Access denied."); } bool superAdmin = GuruxAMI.Server.GXBasicAuthProvider.IsSuperAdmin(s); if (request.DataCollectorIDs != null) { //TODO: check that user can't remove DC that he do not have access. foreach (ulong it in request.DataCollectorIDs) { List<GXAmiDataCollector> item = Db.Select<GXAmiDataCollector>(q => q.Id == it); if (request.Permanently) { Db.Delete(item[0]); } else { if (item.Count != 1) { throw new ArgumentException("Access denied."); } else { item[0].Removed = DateTime.Now.ToUniversalTime(); Db.UpdateOnly(item[0], p => p.Removed, p => p.Id == it); } } events.Add(new GXEventsItem(ActionTargets.DataCollector, Actions.Remove, item[0])); } } } AppHost host = this.ResolveService<AppHost>(); host.SetEvents(Db, this.Request, id, events); return new GXDataCollectorDeleteResponse(); }