public HttpResponseMessage PutUsers(PersonalizationRequsetDTO personalizationrequset) { string callerMethodName = string.Empty; try { //Get Caller Method name from CallerInformation class callerMethodName = CallerInformation.TrackCallerMethodName(); InsightLogger.TrackEvent("PersonalizationAPIController ::endpoint : api/personalizationapi/users/{userID}, action: start put user"); //BL object instances created Personalization personalization = new Personalization(); UserBackend userbackend = new UserBackend(); UserDevice userdevice = new UserDevice(); //if userID is available in requset then check user exist or not. if (personalizationrequset != null && !string.IsNullOrEmpty(personalizationrequset.user.UserID)) { Boolean isUserExists = personalization.CheckUser(personalizationrequset.user.UserID); Boolean isDevicesProvided, isBackendsProvided; //retrackting individual objects from request IEnumerable <UserDeviceDTO> userdevicesdto = personalizationrequset.user.userdevices; IEnumerable <UserBackendDTO> userbackendsdto = personalizationrequset.user.userbackends; UserDTO user = personalizationrequset.user; UserEntity userentity = personalization.UserEntityGenerator(user); IEnumerable <UserDeviceEntity> userprovideddevices = null; IEnumerable <UserBackendEntity> userprovidedbackends = null; //to check if requset has userdevices or not if (userdevicesdto != null) { isDevicesProvided = true; userprovideddevices = userdevice.UserDeviceEntityGenerator(userdevicesdto); } else { isDevicesProvided = false; } //to check if requset has userbackends or not if (userbackendsdto != null) { isBackendsProvided = true; userprovidedbackends = userbackend.UserBackendEntityGenerator(userbackendsdto); } else { isBackendsProvided = false; } UserDTO updateduser; //create if user not exists else update if (!isUserExists) { InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: check user, response: false,userID: " + personalizationrequset.user.UserID); personalization.CreateUser(userentity); InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: create new user, response: success,userID: " + personalizationrequset.user.UserID); //add user devices if provided in request if (isDevicesProvided) { InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: devices provided, response: true"); userdevice.AddDevices(userprovideddevices.ToList()); InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: create and/or associate devices to user, response: success"); } //associate user backends if provided in request other wise associate all backends in system if (isBackendsProvided) { InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: backends provided, response: true"); userbackend.AddBackends(userprovidedbackends.ToList()); InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: create and/or associate backends to user, response: success"); } else { InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: backends provided, response: false"); userbackend.AddAllBackends(user.UserID); InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: create and/or associate all backends to user, response: success"); } updateduser = personalization.GetUser(personalizationrequset.user.UserID); personalization.TriggerUserRequests(personalizationrequset.user.UserID, updateduser.userbackends); InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: trigger a user requests update, response: success"); int SynchTime = personalization.CalcSynchTime(userprovidedbackends); InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: calculate synch waiting time, response: success, synchWaitingtime:" + SynchTime); } else { InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: check user, response: true"); personalization.UpdateUserProp(userentity); //remove existing devices to user and add the provided userdevices in requset if (isDevicesProvided) { InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: devices provided, response: true"); userdevice.RemoveDevices(personalizationrequset.user.UserID); InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: remove all existing associated devices , response: success"); userdevice.AddDevices(userprovideddevices.ToList()); InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: create associated devices to user, response: success"); } //remove existing backends to user and add the provided userbackends in requset if (isBackendsProvided) { InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: backends provided, response: true"); userbackend.RemoveBackends(personalizationrequset.user.UserID); InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: remove all existing associated backends , response: success"); userbackend.AddBackends(userprovidedbackends.ToList()); InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: create associated backends to user, response: success"); } else { userbackend.RemoveBackends(personalizationrequset.user.UserID); } updateduser = personalization.GetUser(personalizationrequset.user.UserID); } var ResponseUser = new PersonalizationResponseDTO <UserDTO>(); ResponseUser.result = updateduser; ResponseUser.query = personalizationrequset; InsightLogger.TrackEvent("PersonalizationAPIController :: endpoint : api/personalizationapi/users/{userID}, action: populate user object to response, response: success, userid: " + personalizationrequset.user.UserID); return(Request.CreateResponse(HttpStatusCode.OK, ResponseUser)); } else { InsightLogger.TrackEvent("PersonalizationAPIController ::endpoint : api/personalizationapi/users/{userID} , action : put user, response : userid is null"); return(Request.CreateResponse(HttpStatusCode.BadRequest, DataProvider.PersonalizationResponseError <UserBackendDTO>("400", "Error in updating user", ""))); } } catch (DataAccessException dalexception) { InsightLogger.Exception(dalexception.Message, dalexception, callerMethodName); return(Request.CreateResponse(HttpStatusCode.NotFound, DataProvider.PersonalizationResponseError <UserDTO>("400", dalexception.Message, dalexception.Message))); } catch (BusinessLogicException blexception) { InsightLogger.Exception(blexception.Message, blexception, callerMethodName); return(Request.CreateResponse(HttpStatusCode.NotFound, DataProvider.PersonalizationResponseError <UserDTO>("400", blexception.Message, blexception.Message))); } catch (Exception exception) { InsightLogger.Exception(exception.Message, exception, callerMethodName); //LoggerHelper.WriteToLog(exception + " - exception in controller action while inserting/updating user : "******"400", exception.Message, exception.StackTrace))); } }