/// <summary> /// method to get single userdevice /// </summary> /// <param name="userID">takes userid as input</param> /// <param name="userDeviceID">takes user device id as input</param> /// <returns>returns user device with id associated to user in the form of personalization response</returns> public PersonalizationResponseDTO <UserDeviceDTO> GetUserDevice(string userID, string userDeviceID) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); UserDeviceDAL userdevicedal = new UserDeviceDAL(); UserDeviceEntity userdeviceentity = userdevicedal.GetUserDevice(userID, userDeviceID); //converting userdevice entity to Response data transfer object var ResponseUserDevice = new PersonalizationResponseDTO <UserDeviceDTO>(); if (userdeviceentity != null) { UserDeviceDTO userdevicedto = UserDeviceEntityDTOMapper(userdeviceentity); ResponseUserDevice.result = userdevicedto; } else { ResponseUserDevice.result = null; } return(ResponseUserDevice); } catch (DataAccessException DALexception) { throw DALexception; } catch (Exception exception) { InsightLogger.Exception(exception.Message, exception, callerMethodName); //LoggerHelper.WriteToLog(exception + " - Error in BL while retreiving single userdevice: " //+exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error); throw new BusinessLogicException(); } }
/// <summary> /// method which converts userdevice entity to dto by using mapper /// </summary> /// <param name="userdeviceentity">takes user device entity as input</param> /// <returns>returns user device dto</returns> public UserDeviceDTO UserDeviceEntityDTOMapper(UserDeviceEntity userdeviceentity) { //convertig entity to data transfer object using mapper UserDeviceDTO userdevicedto = DataProvider.ResponseObjectMapper <UserDeviceDTO, UserDeviceEntity>(userdeviceentity); DeviceDTO devicedto = DataProvider.ResponseObjectMapper <DeviceDTO, UserDeviceEntity>(userdeviceentity); userdevicedto.device = devicedto; return(userdevicedto); }
public async Task <IActionResult> SaveDevice([FromBody] UserDeviceDTO device) { try { if (!ModelState.IsValid) { return(BadRequest("Eksik bilgi girdiniz.")); } var selectedDevice = await _userDevicesRepo.First(d => d.DeviceId == device.DeviceId); if (selectedDevice != null) { selectedDevice.IsLoggedin = true; selectedDevice.UpdateAt = DateTime.UtcNow; var response = await _userDevicesRepo.Update(selectedDevice); if (response) { return(Ok("Cihazınız güncellendi.")); } else { return(BadRequest("Cihazınız güncellenemedi.")); } } else { var response = await _userDevicesRepo.Add(new UserDevice() { Id = new Guid(), UserId = User.GetUserId(), DeviceId = device.DeviceId, Brand = device.Brand, Model = device.Model, OS = device.OS, IsLoggedin = true, }); if (response) { return(Ok("Cihazınız eklendi.")); } else { return(BadRequest("Cihazınız eklenemedi.")); } } } catch (Exception ex) { _logHelper.Log("UserDevicesController", 500, "SaveDevice", ex.Message); return(null); } }
public object ChangeStatus(UserDeviceDTO userDevice) { UserDevice device = this.repository.GetByIds(userDevice.UserId, userDevice.DeviceId); if (device != null && device.ApprovalStatus == ApprovalStatus.Pending) { device.ApprovalStatus = userDevice.Status; this.repository.Save(device); return(new { Success = true }); } return(new { Success = false }); }
/// <summary> /// method which converts userdevice dto to entity by using mapper, first maps devicedto with userdeviceentity /// </summary> /// <param name="userdevicedto">takes user device dto as input</param> /// <returns>returns user backend entity</returns> public UserDeviceEntity UserDeviceDTOEntityMapper(UserDeviceDTO userdevicedto) { //converting input device data transfer object(dto) list to userdevice entity list by using property mapper DeviceDTO devicedto = userdevicedto.device; UserDeviceEntity userdeviceentity = DataProvider.ResponseObjectMapper <UserDeviceEntity, DeviceDTO>(devicedto); //adding missing properties like userID, partitionkey and Rowkey to entity userdeviceentity.DeviceID = string.Concat(userdevicedto.UserID, CoreConstants.AzureTables.UnderScore, userdevicedto.device.DeviceName); userdeviceentity.UserID = userdevicedto.UserID; userdeviceentity.PartitionKey = string.Concat(CoreConstants.AzureTables.UserDevicePK, userdeviceentity.UserID); userdeviceentity.RowKey = userdeviceentity.DeviceID; return(userdeviceentity); }
public async Task <DeviceAssociationResult> EditDeviceWithUserAssociation(UserDeviceAssociation userDevice) { int userId = 0; bool isDeviceAssociationSuccess = false; var deviceId = await _devicerepo.IsDeviceTagExist(userDevice.TagName); if (deviceId > 0) { userId = await _devicerepo.GetUserIdbyDeviceId(deviceId); if (userId == 0) { var userdeviceDto = new UserDeviceDTO() { UserId = userDevice.UserId, DeviceId = deviceId }; await _devicerepo.EditDevice(userdeviceDto, userDevice.DeviceName); isDeviceAssociationSuccess = true; } } return(DeriveDeviceAssociationResult(deviceId, userId, userDevice, isDeviceAssociationSuccess)); }
//Gets the user backend deatils returned by Personalization API public async Task <UserDTO> Getuserdetails() { //creates list Backend model object List <UserBackendDTO> userBackend = new List <UserBackendDTO>(); //creates list Device model object List <UserDeviceDTO> UserDevicedetails = new List <UserDeviceDTO>(); try { //Api Controller object initialization APIController apiControllerObj = new APIController(); //NewUser model object initialization UserDTO userdetails = new UserDTO(); //Gets the user details returned by Personalization API string strUserExisits = await apiControllerObj.Getuserinfo(userid); if (!string.IsNullOrEmpty(strUserExisits)) { //Deseralize the result returned by the API NewuserJsonData newuserjsonResponse = JsonConvert.DeserializeObject <NewuserJsonData>(strUserExisits); //Checks whether the JSON response is not null if (newuserjsonResponse.userResults != null) { UserBackendJsonData userBackendjsonResponse = JsonConvert.DeserializeObject <UserBackendJsonData>(strUserExisits); UserDeviceJsonData userDevicejsonResponse = JsonConvert.DeserializeObject <UserDeviceJsonData>(strUserExisits); //Checks whether the JSON response is not null if (newuserjsonResponse != null) { //Getting All updated user info userdetails.UserID = newuserjsonResponse.userResults.UserID; userdetails.FirstName = newuserjsonResponse.userResults.FirstName; userdetails.LastName = newuserjsonResponse.userResults.LastName; userdetails.Fullname = newuserjsonResponse.userResults.Fullname; userdetails.Email = newuserjsonResponse.userResults.Email; userdetails.Domain = newuserjsonResponse.userResults.Domain; userdetails.DeviceName = newuserjsonResponse.userResults.DeviceName; userdetails.DeviceOS = newuserjsonResponse.userResults.DeviceOS; } //Checks whether the JSON response is not null if (userBackendjsonResponse != null && userBackendjsonResponse.userBackendResults.userBackenddetails != null) { //Iterate user backend json format result and bind to Model foreach (userBackenddetails UserbackendInfo in userBackendjsonResponse.userBackendResults.userBackenddetails) { //Create Model object UserBackendDTO BackendObj = new UserBackendDTO(); BackendObj.UserID = UserbackendInfo.UserID; BackendObj.backend = new BackendDTO(); //setting the properties of Model BackendObj.backend.BackendID = UserbackendInfo.userBackend.BackendID; BackendObj.backend.BackendName = UserbackendInfo.userBackend.BackendName; BackendObj.backend.DefaultUpdateFrequency = UserbackendInfo.userBackend.DefaultUpdateFrequency; BackendObj.backend.AverageAllRequestsLatency = UserbackendInfo.userBackend.AverageAllRequestsLatency; BackendObj.backend.AverageAllRequestsSize = UserbackendInfo.userBackend.AverageAllRequestsSize; BackendObj.backend.AverageRequestLatency = UserbackendInfo.userBackend.AverageRequestLatency; BackendObj.backend.AverageRequestSize = UserbackendInfo.userBackend.AverageRequestSize; BackendObj.backend.ExpectedLatency = UserbackendInfo.userBackend.ExpectedLatency; DateTime?expdate = UserbackendInfo.userBackend.ExpectedUpdate; if (expdate != null) { BackendObj.backend.ExpectedUpdate = expdate.Value; } BackendObj.backend.LastAllRequestsLatency = UserbackendInfo.userBackend.LastAllRequestsLatency; BackendObj.backend.LastAllRequestsSize = UserbackendInfo.userBackend.LastAllRequestsSize; BackendObj.backend.LastRequestLatency = UserbackendInfo.userBackend.LastRequestLatency; BackendObj.backend.LastRequestSize = UserbackendInfo.userBackend.LastRequestSize; DateTime?lstdate = UserbackendInfo.userBackend.LastUpdate; if (lstdate != null) { BackendObj.backend.LastUpdate = lstdate.Value; } BackendObj.backend.OpenApprovals = UserbackendInfo.userBackend.OpenApprovals; BackendObj.backend.OpenRequests = UserbackendInfo.userBackend.OpenRequests; BackendObj.backend.TotalBatchRequestsCount = UserbackendInfo.userBackend.TotalBatchRequestsCount; BackendObj.backend.TotalRequestsCount = UserbackendInfo.userBackend.TotalRequestsCount; BackendObj.backend.UpdateTriggered = UserbackendInfo.userBackend.UpdateTriggered; BackendObj.backend.UrgentApprovals = UserbackendInfo.userBackend.UrgentApprovals; // BackendObj.backend.MissingConfirmationsLimit = UserbackendInfo.userBackend.MissingConfirmationsLimit; //Adding the Model object to the list userBackend.Add(BackendObj); userdetails.userbackends = userBackend; } } //Checks whether the JSON response is not null if (userDevicejsonResponse != null && userDevicejsonResponse.userDevicesResults.userDevicedetails != null) { //Iterate user devices json format result and bind to Model foreach (userDevicedetails userDeviceInfo in userDevicejsonResponse.userDevicesResults.userDevicedetails) { //Create Model object UserDeviceDTO deviceObj = new UserDeviceDTO(); // Get user device details deviceObj.UserID = userDeviceInfo.UserID; deviceObj.device = new DeviceDTO(); deviceObj.device.DeviceID = userDeviceInfo.userDevices.DeviceID; deviceObj.device.DeviceName = userDeviceInfo.userDevices.DeviceName; deviceObj.device.DeviceBrand = userDeviceInfo.userDevices.DeviceBrand; deviceObj.device.DeviceModel = userDeviceInfo.userDevices.DeviceModel; deviceObj.device.maxSynchReplySize = userDeviceInfo.userDevices.maxSynchReplySize; // Add details to new model UserDevicedetails.Add(deviceObj); userdetails.userdevices = UserDevicedetails; } } } } //Return user details as list object return(userdetails); } catch (Exception exception) { LoggerHelper.WriteToLog(exception + " - Error while creating client context : " + exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error); throw new DataAccessException("Error in Getuserdetails"); } }
public UserDeviceDTO RegisterDeviceForPushNotification(int id, UserTypes userType, UserDevice device) { UserDeviceDTO response = new UserDeviceDTO(); if (userType == UserTypes.User) { User user = _dbContext.Users.Include(x => x.UserDevices).FirstOrDefault(x => x.Id == id); if (user != null) { UserDevice existingUserDevice = user.UserDevices.FirstOrDefault(x => x.UDID.Equals(device.UDID)); if (existingUserDevice == null) { PushNotificationsUtil.ConfigurePushNotifications(device); user.UserDevices.Add(device); _dbContext.SaveChanges(); response = Mapper.Map <UserDevice, UserDeviceDTO>(device); return(response); } else { _dbContext.UserDevices.FirstOrDefault(x => x.UDID == existingUserDevice.UDID && x.IsActive == true).IsActive = false; existingUserDevice.Driver_Id = null; existingUserDevice.User_Id = user.Id; existingUserDevice.IsActive = true; _dbContext.SaveChanges(); PushNotificationsUtil.ConfigurePushNotifications(existingUserDevice); response = Mapper.Map <UserDevice, UserDeviceDTO>(existingUserDevice); return(response); } } else { return(null); } } else if (userType == UserTypes.Driver) { Driver driver = _dbContext.Drivers.Include(x => x.DriverDevices).FirstOrDefault(x => x.Id == id); if (driver != null) { UserDevice existingDevice = driver.DriverDevices.FirstOrDefault(x => x.UDID.Equals(device.UDID)); if (existingDevice == null) { PushNotificationsUtil.ConfigurePushNotifications(device); driver.DriverDevices.Add(device); _dbContext.SaveChanges(); response = Mapper.Map <UserDevice, UserDeviceDTO>(device); return(response); } else { _dbContext.UserDevices.FirstOrDefault(x => x.UDID == existingDevice.UDID && x.IsActive == true).IsActive = false; existingDevice.User_Id = null; existingDevice.Driver_Id = driver.Id; existingDevice.IsActive = true; _dbContext.SaveChanges(); PushNotificationsUtil.ConfigurePushNotifications(existingDevice); response = Mapper.Map <UserDevice, UserDeviceDTO>(existingDevice); return(response); } } else { return(null); } } else { return(null); } }