public static async Task<int> CreateRequestDevice(RequestDevice newApp) { int num = 0; string str = (string)null; var device = await DeviceDal.GetDevice(newApp.ClientId, newApp.DeviceKey); if (device == null) { var exit = await RequestDeviceDal.IsExistRequestDevice(newApp.ClientId, newApp.DeviceKey); if (!exit) await RequestDeviceDal.CreateRequestDevice(newApp); else await RequestDeviceDal.UpdateRequestDevice(newApp); RequestDevice requestDevice = await RequestDeviceDal.GetRequestDevice(newApp.ClientId, newApp.DeviceKey); if (requestDevice != null) { if (!requestDevice.IsApproved) //str = string.Format("R{0}", (object)requestDevice.Id.ToString("D4")); num = (int)requestDevice.Id; else num = 3; } else num = 2; } else num = 1; return num; }
public static async Task<long> UpdateRequestDevice(RequestDevice newApp, bool isApproved) { if (isApproved) { const string commandText = @"Update RequestDevices Set ClientId=@clientId, SerialNumber=@serialNumber, IMEI=@iMEI, Manufacturer=@manufacturer, Model=@model, Platform=@platform, PlatformVersion=@platformVersion, IsApproved = @isApproved, Updated = @updated Where DeviceKey = @deviceKey"; var parameters = new DynamicParameters(); parameters.Add("clientId", newApp.ClientId); parameters.Add("deviceKey", newApp.DeviceKey); parameters.Add("serialNumber", newApp.SerialNumber); parameters.Add("iMEI", newApp.IMEI); parameters.Add("manufacturer", newApp.Manufacturer); parameters.Add("model", newApp.Model); parameters.Add("platform", newApp.Platform); parameters.Add("platformVersion", newApp.PlatformVersion); parameters.Add("isApproved", isApproved); parameters.Add("updated", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); // if (isApproved) long results; using (var conn = await DataAccessBase.GetOpenAsync(DataAccessBase.QuangAuthConn)) { var data = await conn.QueryAsync<long>(commandText, parameters); results = data.FirstOrDefault(); } return results; } else { const string commandText = @"Update RequestDevices Set ClientId=@clientId, SerialNumber=@serialNumber, IMEI=@iMEI, Manufacturer=@manufacturer, Model=@model, Platform=@platform, PlatformVersion=@platformVersion, Created = @created Where DeviceKey = @deviceKey and IsApproved = @isApproved"; var parameters = new DynamicParameters(); parameters.Add("clientId", newApp.ClientId); parameters.Add("deviceKey", newApp.DeviceKey); parameters.Add("serialNumber", (object)newApp.SerialNumber); parameters.Add("iMEI", (object)newApp.IMEI); parameters.Add("manufacturer", (object)newApp.Manufacturer); parameters.Add("model", (object)newApp.Model); parameters.Add("platform", (object)newApp.Platform); parameters.Add("platformVersion", (object)newApp.PlatformVersion); parameters.Add("isApproved", isApproved); parameters.Add("created", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); long results; using (var conn = await DataAccessBase.GetOpenAsync(DataAccessBase.QuangAuthConn)) { var data = await conn.QueryAsync<long>(commandText, parameters); results = data.FirstOrDefault(); } return results; } }
public static async Task<long> UpdateRequestDevice(RequestDevice newApp) { return await UpdateRequestDevice(newApp, false); }
public static async Task< long> CreateRequestDevice(RequestDevice newApp) { const string commandText = @"Insert into RequestDevices (Id, ClientId, DeviceKey, SerialNumber, IMEI, Manufacturer, Model, Platform, PlatformVersion, IsApproved, Created, Updated) " + "values (@id, @clientId, @deviceKey, @serialNumber, @iMEI, @manufacturer, @model, @platform, @platformVersion, @isApproved, @created, @updated)"; var parameters = new DynamicParameters(); parameters.Add("clientId", newApp.ClientId); parameters.Add("deviceKey", newApp.DeviceKey); parameters.Add("serialNumber", newApp.SerialNumber); parameters.Add("iMEI", newApp.IMEI); parameters.Add("manufacturer", newApp.Manufacturer); parameters.Add("model", newApp.Model); parameters.Add("platform", newApp.Platform); parameters.Add("platformVersion", newApp.PlatformVersion); parameters.Add("isApproved", false); parameters.Add("updated", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); parameters.Add("created", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); long results; using (var conn = await DataAccessBase.GetOpenAsync(DataAccessBase.QuangAuthConn)) { var data = await conn.QueryAsync<long>(commandText, parameters); results = data.FirstOrDefault(); } return results; }
public IEnumerable<RequestDevice> GetPaging(int pageSize, int pageNumber, string clientId, string keyword, DateTime? dateFrom, DateTime? dateTo) { var parameters = new Dictionary<string, object>(); string str = "select *, EXISTS(SELECT * FROM TrustDevices WHERE TrustDevices.DeviceSerial = RequestDevices.SerialNumber) as IsTrust\n from RequestDevices \n where IsApproved = false and (Id = @id or DeviceKey LIKE @param)"; int num1 = 0; if (!string.IsNullOrEmpty(keyword)) { Match match = Regex.Match(keyword, "^R([\\d]{4,})$"); if (match.Success) num1 = int.Parse(match.Groups[1].Value); } parameters.Add("@id", num1); parameters.Add("@param", "%" + Utils.EncodeForLike(keyword) + "%"); if (!string.IsNullOrEmpty(clientId)) { str += " and ClientId = @clientId"; parameters.Add("@clientId", clientId); } if (dateFrom.HasValue) { str += " and Created >= @dateFrom"; parameters.Add("@dateFrom", dateFrom.Value.ToString("yyyy-MM-dd 00:00:00")); } if (dateTo.HasValue) { str += " and Created <= @dateTo"; parameters.Add("@dateTo", dateTo.Value.ToString("yyyy-MM-dd 23:59:59")); } string commandText = str + " order by Created limit @rowNumber, @pageSize"; parameters.Add("@rowNumber", pageSize * pageNumber); parameters.Add("@pageSize", pageSize); var list = new List<RequestDevice>(); foreach (Dictionary<string, string> dictionary in _database.Query(commandText, parameters)) { var requestDevice = new RequestDevice { Id = int.Parse(dictionary["Id"]), ClientId = dictionary["ClientId"], IsApproved = bool.Parse(dictionary["IsApproved"]), DeviceKey = dictionary["DeviceKey"], SerialNumber = dictionary["SerialNumber"], IMEI = dictionary["IMEI"], Manufacturer = dictionary["Manufacturer"], Model = dictionary["Model"], Platform = dictionary["Platform"], PlatformVersion = dictionary["PlatformVersion"], Created = DateTime.Parse(dictionary["Created"]) }; if (!string.IsNullOrEmpty(dictionary["Updated"])) requestDevice.Updated = DateTime.Parse(dictionary["Updated"]); if (!string.IsNullOrEmpty(dictionary["IsTrust"])) { int num2 = int.Parse(dictionary["IsTrust"]); requestDevice.IsTrust = num2 > 0; } list.Add(requestDevice); } return list; }
public RequestDevice GetRequestDevice(string clientId, string deviceKey) { List<Dictionary<string, string>> list = _database.Query("select * from RequestDevices where ClientId=@clientId and DeviceKey = @deviceKey and IsApproved = @isApproved", new Dictionary<string, object> { { "@clientId", clientId }, { "@deviceKey", deviceKey }, { "@isApproved", false } }); var requestDevice = (RequestDevice)null; if (list != null && list.Count == 1) { Dictionary<string, string> dictionary = list[0]; requestDevice = new RequestDevice { Id = int.Parse(dictionary["Id"]), ClientId = dictionary["ClientId"], IsApproved = bool.Parse(dictionary["IsApproved"]), DeviceKey = dictionary["DeviceKey"], SerialNumber = dictionary["SerialNumber"], IMEI = dictionary["IMEI"], Manufacturer = dictionary["Manufacturer"], Model = dictionary["Model"], Platform = dictionary["Platform"], PlatformVersion = dictionary["PlatformVersion"], Created = DateTime.Parse(dictionary["Created"]), Updated = DateTime.Parse(dictionary["Updated"]) }; } return requestDevice; }