public async Task <ActionResult> AddUUIDBySerialNumber(RequestScanQRCode request) { try { if (string.IsNullOrEmpty(request.uuid)) { return(Json(new { success = ResponseStatus.Error, responseText = "uuid must not be null" })); } if (string.IsNullOrEmpty(request.serialnumber)) { return(Json(new { success = ResponseStatus.Error, responseText = "serialnumber must not be null" })); } if (string.IsNullOrEmpty(request.phoneType)) { return(Json(new { success = ResponseStatus.Error, responseText = "phoneType must not be null" })); } if (string.IsNullOrEmpty(request.devicetoken)) { return(Json(new { success = ResponseStatus.Error, responseText = "devicetoken must not be null" })); } if (string.IsNullOrEmpty(request.phonenumber)) { return(Json(new { success = ResponseStatus.Error, responseText = "phonenumber must not be null" })); } var response = new ResponseData <Dashboard>(); string url = _appSettings.ApiUrl + "/Home/AddUUIDBySerialNumber"; client.BaseAddress = new Uri(url); HttpResponseMessage responseMessage = await client.PostAsJsonAsync(url, request); var responseData = new ResponseData <Dashboard>(); if (responseMessage.IsSuccessStatusCode) { responseData = responseMessage.Content.ReadAsAsync <ResponseData <Dashboard> >().Result; } return(Json(new { success = responseData.Status, responseText = responseData.Message })); } catch (Exception ex) { return(Json(new { success = ResponseStatus.Error, responseText = ex.Message })); } }
public ResponseData <Dashboard> AddUUIDBySerialNumber([FromBody] RequestScanQRCode request) { try { bool isNew = true; var response = new ResponseData <Dashboard>(); var appliance = _applianceService.GetApplianceBySerialNumber(request.serialnumber); if (appliance != null) { var lAccountAppliance = _accountApplianceService.GetAccountApplianceByUUID(request.uuid); if (lAccountAppliance != null && lAccountAppliance.Count > 0) { foreach (var item in lAccountAppliance) { if (item.ApplianceId == appliance.Id) { isNew = false; } } if (isNew) { var accAppliance = new AccountAppliance() { IdentifierForVendor = request.uuid, IsQRCodeScaned = true, DeviceName = request.devicename, Lat = Convert.ToDouble(request.latitude), Lon = Convert.ToDouble(request.longitude), ApplianceId = appliance.Id, AccountId = lAccountAppliance.FirstOrDefault().AccountId, PhoneType = request.phoneType, DeviceToken = request.devicetoken }; _accountApplianceService.Insert(accAppliance); var account = _accountService.GetAccountById(accAppliance.AccountId.Value); //Record event QR code var _event = new Event() { AccountId = accAppliance.AccountId, ApplianceId = accAppliance.ApplianceId, EventTypeId = Constant.EventType.ApplianceQRCodeScanned, Timestamp = DateTime.UtcNow, Message = account.PhoneNumber + " Pending" }; _eventService.Insert(_event); } else { response.Status = ResponseStatus.Existed.ToString(); response.Message = ResponseMessage.SerialNumberIsExist; return(response); } } else { var acc = _accountService.GetAccountByPhoneNumber(request.phonenumber); var accAppliance = new AccountAppliance() { IdentifierForVendor = request.uuid, IsQRCodeScaned = true, DeviceName = request.devicename, Lat = Convert.ToDouble(request.latitude), Lon = Convert.ToDouble(request.longitude), ApplianceId = appliance.Id, AccountId = acc.Id, PhoneType = request.phoneType, DeviceToken = request.devicetoken }; _accountApplianceService.Insert(accAppliance); //Record event QR code var _event = new Event() { AccountId = accAppliance.AccountId, ApplianceId = accAppliance.ApplianceId, EventTypeId = Constant.EventType.ApplianceQRCodeScanned, Timestamp = DateTime.UtcNow, Message = request.phonenumber + " Pending" }; _eventService.Insert(_event); } response.Message = ResponseMessage.Success; } else { response.Message = ResponseMessage.SerialNumberInCorrect; } response.Status = ResponseStatus.Success.ToString(); return(response); } catch (Exception ex) { var response = new ResponseData <Dashboard>(); response.Message = ex.Message; response.Status = ResponseStatus.Error.ToString(); return(response); } }