public HttpResponseMessage AddAssociateDevicewithVehicle(VehicleDeviceMapDet objUserDeviceMapDet, string Token, string AppKey) { string strJson = string.Empty; var response = this.Request.CreateResponse(HttpStatusCode.OK); try { Accountmeg objaccountmegment = new Accountmeg(); string result = objaccountmegment.Getresult(AppKey, Token); if (result == "true") { using (TTPAPIDataContext DB = new TTPAPIDataContext()) { var checkUserDeviceMapDet = DB.VehicleDeviceMapDets.Where(x => x.vehicleId == objUserDeviceMapDet.vehicleId).FirstOrDefault(); if (checkUserDeviceMapDet == null) { VehicleDeviceMapDet objUserDeviceMapDets = new VehicleDeviceMapDet(); objUserDeviceMapDets.DeviceId = objUserDeviceMapDet.DeviceId; objUserDeviceMapDets.vehicleId = objUserDeviceMapDet.vehicleId; // objUserDeviceMapDets.MappedDateTime = DateTime.Now; // objUserDeviceMapDets.MappedBy = String.Format("{0}{1}", Token.Substring(0, 36), DateTime.Now.ToShortDateString()); objUserDeviceMapDets.IsActive = true; DB.VehicleDeviceMapDets.InsertOnSubmit(objUserDeviceMapDets); DB.SubmitChanges(); strJson = "{\"Result\":\"204\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } else { strJson = "{\"Result\":\"VehicalId Is Already Use\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } } } else { strJson = "{\"Result\":\"Invalide AppKey\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } } catch (Exception ex) { strJson = "{\"Result\":\"" + ex.Message + "\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } }
public HttpResponseMessage DisassociateDevicewithVehicle(VehicleDeviceMapDet objUserDeviceMapDet, string Token, string AppKey) { string strJson = string.Empty; var response = this.Request.CreateResponse(HttpStatusCode.OK); try { Accountmeg objaccountmegment = new Accountmeg(); string result = objaccountmegment.Getresult(AppKey, Token); if (result == "true") { using (TTPAPIDataContext DB = new TTPAPIDataContext()) { VehicleDeviceMapDet objUserDeviceMapDets = new VehicleDeviceMapDet(); var objDisassociate = (from udm in DB.VehicleDeviceMapDets where objUserDeviceMapDet.vehicleId == udm.vehicleId && udm.DeviceId == objUserDeviceMapDet.DeviceId select new { udm }).FirstOrDefault(); if (objDisassociate != null) { objDisassociate.udm.IsActive = false; // objDisassociate.udm.MappedDateTime = DateTime.Now; DB.SubmitChanges(); strJson = "{\"Result\":\"204\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } else { strJson = "{\"Result\":\"100\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } } } else { strJson = "{\"Result\":\"Invalide AppKey\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } } catch (Exception ex) { strJson = "{\"Result\":\"" + ex.Message + "\"}"; response.Content = new StringContent(strJson, Encoding.UTF8, "application/json"); return(response); } }