public ActionResult <DeleteScheduleTargetResponse> Post(DeleteScheduleTarget request)
        {
            if (request.Schedules == null || request.Schedules.Length == 0)
            {
                return(BadRequest("Schedules array is empty."));
            }
            if (request.Attributes == null || request.Attributes.Length == 0)
            {
                return(BadRequest("Attributes array is empty."));
            }
            List <GXScheduleToAttribute> list = new List <GXScheduleToAttribute>();

            foreach (UInt64 s in request.Schedules)
            {
                foreach (UInt64 o in request.Attributes)
                {
                    list.Add(new GXScheduleToAttribute()
                    {
                        ScheduleId = s, AttributeId = o
                    });
                }
            }
            host.Connection.Delete(GXDeleteArgs.DeleteRange(list));
            host.SetChange(TargetType.Schedule, DateTime.Now);
            return(new DeleteScheduleTargetResponse());
        }
Beispiel #2
0
        public void RemoveUserRolesTest()
        {
            GXUser user = new GXUser();

            user.Id       = "642c8f77-aeeb-4e86-86db-1a8b1b2fc982";
            user.UserName = "******";
            List <string> roles = new List <string>();

            roles.Add("Admin");
            roles.Add("User");
            roles.Add("DeviceManager");
            roles.Add("SystemErrorManager");
            GXSelectArgs sel = GXSelectArgs.Select <GXRole>(q => GXSql.One);

            sel.Where.And <GXUserRole>(q => q.UserId == user.Id);
            sel.Where.And <GXRole>(q => !roles.Contains(q.Name));
            GXDeleteArgs d = GXDeleteArgs.Delete <GXUserRole>(q => q.UserId == user.Id);

            d.Where.And <GXRole>(q => GXSql.Exists <GXUserRole, GXRole>(q => q.RoleId, q => q.Id, sel));

            /*
             * GXSelectArgs sel = GXSelectArgs.Select<GXUserRole>(q => q.UserId, q => q.UserId == "642c8f77-aeeb-4e86-86db-1a8b1b2fc982");
             * sel.Joins.AddInnerJoin<GXUserRole, GXRole>(a => a.RoleId, b => b.Id);
             * sel.Where.And<GXRole>(q => !roles.Contains(q.Name));
             * GXDeleteArgs d = GXDeleteArgs.Delete<GXUserRole>(q => GXSql.Exists(sel));
             */
            Assert.AreEqual("", d.ToString());
        }
 public ActionResult <DeleteScheduleResponse> Post(DeleteSchedule request)
 {
     //Remove mapping.
     if (request.AttributeIds != null && request.ScheduleIds != null)
     {
         for (int pos = 0; pos != request.AttributeIds.Length; ++pos)
         {
             GXDeleteArgs arg = GXDeleteArgs.Delete <GXScheduleToAttribute>(q => request.ScheduleIds[pos] == q.ScheduleId);
             arg.Where.And <GXScheduleToAttribute>(q => request.AttributeIds[pos] == q.AttributeId);
             host.Connection.Delete(arg);
         }
         host.SetChange(TargetType.Schedule, DateTime.Now);
     }
     else if (request.ScheduleIds != null)
     {
         GXSelectArgs      arg  = GXSelectArgs.Select <GXSchedule>(a => a.Id, q => request.ScheduleIds.Contains(q.Id));
         List <GXSchedule> list = host.Connection.Select <GXSchedule>(arg);
         DateTime          now  = DateTime.Now;
         foreach (GXSchedule it in list)
         {
             it.Removed = now;
             host.Connection.Update(GXUpdateArgs.Update(it, q => q.Removed));
         }
         host.SetChange(TargetType.Schedule, now);
     }
     return(new DeleteScheduleResponse());
 }
Beispiel #4
0
        public void DeleteByPrimaryKeyTest()
        {
            TestClass t = new TestClass();

            t.Id = 1;
            GXDeleteArgs arg = GXDeleteArgs.DeleteById <TestClass>(1);

            Assert.AreEqual("DELETE FROM TestClass WHERE ID=1", arg.ToString());
        }
 public ActionResult <DeleteTaskResponse> Post(DeleteTask request)
 {
     if (request.Ids != null)
     {
         host.Connection.Delete(GXDeleteArgs.Delete <GXTask>(q => request.Ids.Contains(q.Id)));
         host.SetChange(TargetType.Tasks, DateTime.Now);
     }
     return(new DeleteTaskResponse());
 }
Beispiel #6
0
 public ActionResult <ClearDeviceLogResponse> Post(ClearDeviceLog request)
 {
     if (request.Ids != null)
     {
         host.Connection.Delete(GXDeleteArgs.Delete <GXError>(q => request.Ids.Contains(q.DeviceId)));
     }
     else
     {
         host.Connection.Delete(GXDeleteArgs.DeleteAll <GXError>());
     }
     host.SetChange(TargetType.DeviceLog, DateTime.Now);
     return(new ClearDeviceLogResponse());
 }
 public ActionResult <RemoveReaderResponse> Post(RemoveReader request)
 {
     if (request.Ids != null)
     {
         host.Connection.Delete(GXDeleteArgs.Delete <GXReaderInfo>(q => request.Ids.Contains(q.Id)));
     }
     else
     {
         host.Connection.Delete(GXDeleteArgs.DeleteAll <GXReaderInfo>());
     }
     host.SetChange(TargetType.Readers, DateTime.Now);
     return(new RemoveReaderResponse());
 }
Beispiel #8
0
        public ActionResult <ReaderDevicesUpdateResponse> RemoveDevicesFromReaders(ReaderDevicesUpdate request)
        {
            List <GXDeviceToReader> list = new List <GXDeviceToReader>();

            for (int pos = 0; pos != request.Readers.Length; ++pos)
            {
                GXDeviceToReader it = new GXDeviceToReader();
                it.ReaderId = request.Readers[pos];
                it.DeviceId = request.Devices[pos];
                list.Add(it);
            }
            host.Connection.Delete(GXDeleteArgs.DeleteRange(list));
            host.SetChange(TargetType.Readers | TargetType.Device, DateTime.Now);
            return(new ReaderDevicesUpdateResponse());
        }
        public ActionResult <DeleteScheduleTargetResponse> Post(DeleteScheduleTarget request)
        {
            List <GXScheduleToAttribute> list = new List <GXScheduleToAttribute>();

            foreach (UInt64 s in request.Schedules)
            {
                foreach (UInt64 o in request.Attributes)
                {
                    list.Add(new GXScheduleToAttribute()
                    {
                        ScheduleId = s, AttributeId = o
                    });
                }
            }
            host.Connection.Delete(GXDeleteArgs.DeleteRange(list));
            host.SetChange(TargetType.Schedule, DateTime.Now);
            return(new DeleteScheduleTargetResponse());
        }
 public ActionResult <ClearSystemErrorResponse> Post(ClearSystemError request)
 {
     host.Connection.Delete(GXDeleteArgs.DeleteAll <GXSystemError>());
     host.SetChange(TargetType.SystemError, DateTime.Now);
     return(new ClearSystemErrorResponse());
 }