/// <summary> /// method to delete single userdevice /// </summary> /// <param name="userID">takes userid as input</param> /// <param name="userDeviceID">takes user device id as input</param> /// <returns>returns deleted user backend entity</returns> public UserDeviceEntity DeleteUserDevice(string userID, string userDeviceID) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); UserDeviceDAL userdevicedal = new UserDeviceDAL(); //calling data access layer method UserDeviceEntity userdeviceentity = userdevicedal.DeleteUserDevice(userID, userDeviceID); return(userdeviceentity); } catch (DataAccessException DALexception) { throw DALexception; } catch (Exception exception) { InsightLogger.Exception(exception.Message, exception, callerMethodName); //LoggerHelper.WriteToLog(exception + " - Error in BL while deleting single userdevice : " //+exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error); throw new BusinessLogicException(); } }
public void Save(TweetModel tweetModel) { var userId = _tweetContext.Users.Where(x => x.Username == tweetModel.Username).Select(x => x.UserId).FirstOrDefault(); var twittedBy = _tweetContext.Users.Where(x => x.Username == tweetModel.TwittedBy).Select(x => x.UserId).FirstOrDefault(); // TODO: User device should come from UI/Client once user logs in to the APP. var userDeviceId = _tweetContext.UserDevices.Where(x => x.UserId == twittedBy).Select(x => x.UserDeviceId).FirstOrDefault(); // user tweets from new device if (userDeviceId == 0) { UserDeviceEntity userDeviceEntity = new UserDeviceEntity() { UserId = userId, DeviceName = "Test device", // TODO: Pass device name from UI/Client DeviceTypeId = (int)UserDeviceType.Desktop, // TODO: Pass device type from UI/Client }; _tweetContext.UserDevices.Add(userDeviceEntity); _tweetContext.SaveChanges(); } var tweetEntity = new TweetEntity() { TweetContent = tweetModel.TweetContent, TwittedBy = twittedBy, UserId = userId, UserDeviceId = userDeviceId, TweetTime = DateTime.Now }; _tweetContext.Tweets.Add(tweetEntity); _tweetContext.SaveChanges(); }
/// <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(); } }
protected override async Task <IUserRelation> GetUserRelation(int id) { UserDeviceEntity userDevice = await repository.GetEntities <UserDeviceEntity>() .FirstOrDefaultAsync(x => x.DeviceId == id); return(userDevice); }
/// <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); }
/// <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 HttpResponseMessage DeleteUserDevice(string userID, string userDeviceID) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); InsightLogger.TrackEvent("PersonalizationAPIController :: delete method, endpoint - api/personalizationapi/users/{userID}/devices/{userDeviceID}"); //checks userid and userdeviceis for null if (!(string.IsNullOrEmpty(userID) || string.IsNullOrEmpty(userDeviceID))) { UserDevice userdevice = new UserDevice(); InsightLogger.TrackEvent("PersonalizationAPIController :: delete specific Associated device to user"); UserDeviceEntity deleteUserDeviceEntity = userdevice.DeleteUserDevice(userID, userDeviceID); //if user has associated device deleted return ok otherwise not found if (deleteUserDeviceEntity != null) { return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } else { InsightLogger.TrackEvent("PersonalizationAPIController ::userid or userdeviceid is null"); return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } catch (DataAccessException dalexception) { InsightLogger.Exception(dalexception.Message, dalexception, callerMethodName); return(Request.CreateResponse(HttpStatusCode.NotFound, DataProvider.PersonalizationResponseError <UserDeviceDTO>("400", dalexception.Message, dalexception.Message))); } catch (BusinessLogicException blexception) { InsightLogger.Exception(blexception.Message, blexception, callerMethodName); return(Request.CreateResponse(HttpStatusCode.NotFound, DataProvider.PersonalizationResponseError <UserDeviceDTO>("400", blexception.Message, blexception.Message))); } catch (Exception exception) { //LoggerHelper.WriteToLog(exception + " - exception in controller action while deleting single userdevcie with deviceID : " // + exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error); InsightLogger.Exception(exception.Message, exception, callerMethodName); return(Request.CreateResponse(HttpStatusCode.NotFound, DataProvider.PersonalizationResponseError <UserDeviceDTO>("400", exception.Message, exception.StackTrace))); } }
/// <summary> /// method to delete single userdevice /// </summary> /// <param name="userID">takes userid as input</param> /// <param name="userDeviceID">takes user device id as input</param> /// <returns>returns deleted user device entity</returns> public UserDeviceEntity DeleteUserDevice(string userID, string userDeviceID) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); //call dataprovider method to delete entities from azure table UserDeviceEntity deleteUserDeviceEntity = DataProvider.DeleteEntity <UserDeviceEntity>(CoreConstants.AzureTables.UserDeviceConfiguration, string.Concat(CoreConstants.AzureTables.UserDevicePK, userID), userDeviceID); return(deleteUserDeviceEntity); } catch (Exception exception) { InsightLogger.Exception(exception.Message, exception, callerMethodName); //LoggerHelper.WriteToLog(exception + " - Error while deleting userdevice from userdeviceconfig azure table in DAL : " //+ exception.ToString(), CoreConstants.Priority.High, CoreConstants.Category.Error); throw new DataAccessException(); } }