예제 #1
0
        public string UpdateLoginDevicesRest(LoginDevicesDataContract loginDevice)
        {
            var result = new Result <object>();

            try
            {
                using (var ctx = new PolicyProjectEntities())
                {
                    var existed = ctx.tbl_login_devices.FirstOrDefault(
                        x => x.id_device == loginDevice.DeviceId && x.id_login == loginDevice.LoginId);

                    if (existed == null)
                    {
                        throw new Exception(string.Concat("Не найдено устройство с ИД ", loginDevice.DeviceId,
                                                          ", принадлежащий логину с ИД ", loginDevice.LoginId));
                    }

                    existed.need_update_device = loginDevice.NeedUpdateDevice;
                    result.BoolRes             = ctx.SaveChanges() > 0;
                }
            }
            catch (Exception ex)
            {
                result.BoolRes  = false;
                result.ErrorRes = string.Concat("Ошибка обновления статуса устройства. ", ex.Message);
            }

            return(JsonConvert.SerializeObject(result));
        }
예제 #2
0
        public Result <LoginDevicesDataContract[]> GetLoginDevices(LoginDevicesDataContract loginDevicesFilter)
        {
            var result = new Result <LoginDevicesDataContract[]>();

            try
            {
                using (var ctx = new PolicyProjectEntities())
                {
                    if (loginDevicesFilter == null)
                    {
                        result.SomeResult =
                            ctx.tbl_login_devices.Select(
                                loginDevicesTblData => new LoginDevicesDataContract
                        {
                            LoginDeviceId    = loginDevicesTblData.id,
                            DeviceId         = loginDevicesTblData.id_device,
                            LoginId          = loginDevicesTblData.id_login,
                            NeedUpdateDevice = loginDevicesTblData.need_update_device
                        })
                            .ToArray();
                    }
                    else
                    {
                        result.SomeResult =
                            ctx.tbl_login_devices.Where(
                                x =>
                                (loginDevicesFilter.LoginDeviceId > 0 &&
                                 x.id == loginDevicesFilter.LoginDeviceId) ||
                                (loginDevicesFilter.LoginId > 0 && x.id_login == loginDevicesFilter.LoginId)
                                ||
                                (loginDevicesFilter.DeviceId > 0 && x.id_device == loginDevicesFilter.DeviceId))
                            .Select(
                                loginDevicesTblData => new LoginDevicesDataContract
                        {
                            LoginDeviceId    = loginDevicesTblData.id,
                            DeviceId         = loginDevicesTblData.id_device,
                            LoginId          = loginDevicesTblData.id_login,
                            NeedUpdateDevice = loginDevicesTblData.need_update_device
                        }).ToArray();
                    }

                    result.BoolRes = true;
                }
            }
            catch (Exception ex)
            {
                result.BoolRes  = false;
                result.ErrorRes = string.Concat("Ошибка получения списка устройств. ", ex.Message);
            }

            return(result);
        }
        public static tbl_login_devices FromLoginDeviceDataContractToTblLoginDevice(
            LoginDevicesDataContract loginDeviceData)
        {
            if (loginDeviceData.LoginDeviceId < 1 || loginDeviceData.LoginId < 1 || loginDeviceData.DeviceId < 1)
            {
                return(null);
            }

            return(new tbl_login_devices
            {
                id = loginDeviceData.LoginDeviceId,
                id_login = loginDeviceData.LoginId,
                id_device = loginDeviceData.DeviceId,
                need_update_device = loginDeviceData.NeedUpdateDevice
            });
        }
        public static bool Compare(LoginDevicesDataContract obj1, LoginDevicesDataContract obj2)
        {
            if (obj1 == null && obj2 == null)
            {
                return(true);
            }

            if (obj1 == null && obj2 != null)
            {
                return(false);
            }

            if (obj1 != null && obj2 == null)
            {
                return(false);
            }

            return(obj1.LoginDeviceId == obj2.LoginDeviceId && obj1.DeviceId == obj2.DeviceId &&
                   obj1.LoginId == obj2.LoginId);
        }
예제 #5
0
        public string GetLoginDevicesRest(LoginDevicesDataContract loginDevicesFilter)
        {
            var queryResult = GetLoginDevices(loginDevicesFilter);

            return(JsonConvert.SerializeObject(queryResult));
        }