/// <summary> /// Add client /// </summary> /// <param name="headerInfo"> </param> /// <param name="eventClient"></param> /// <param name="linkInitialSet"> </param> /// <returns></returns> public ClientAddResponse ClientAddFull(ClientAddRequest clientAddRequest) { var response = new ClientAddResponse(); // This is a new client. // if (string.IsNullOrEmpty(clientAddRequest.eventClient.Name)) { response.responseStatus = new ResponseStatus() { ReturnCode = -0010, ReasonCode = 0001, Message = "Client Name is mandatory." }; return(response); } // -------------------------------------------------------------- // Check if user ID is already connected to a client // -------------------------------------------------------------- #region Check if user is already connected to a client if (!string.IsNullOrEmpty(clientAddRequest.eventClient.FKUserID)) { var checkLinkedUser = new Client(clientAddRequest.headerInfo) { FKUserID = clientAddRequest.eventClient.FKUserID }; //var responseLinked = checkLinkedUser.ReadLinkedUser(); var responseLinked = RepClient.ReadLinkedUser(checkLinkedUser); if (!responseLinked.Successful) { response.responseStatus = new ResponseStatus(); response.responseStatus = responseLinked; return(response); } if (responseLinked.ReturnCode == 0001 && responseLinked.ReasonCode == 0001) { response.responseStatus = new ResponseStatus() { ReturnCode = -0010, ReasonCode = 0002, Message = "User ID is already linked to another client." }; return(response); } } #endregion var newClientUid = 0; using (var connection = new MySqlConnection(ConnString.ConnectionString)) { using (var tr = new TransactionScope(TransactionScopeOption.Required)) { connection.Open(); // ------------------------------- // Call method to add new client // ------------------------------- //var newClient = clientAddRequest.eventClient.Insert(clientAddRequest.headerInfo, connection); var newClient = RepClient.Insert(clientAddRequest.headerInfo, clientAddRequest.eventClient, connection); // var newClientX = eventClient.MySQLInsert(headerInfo); newClientUid = Convert.ToInt32(newClient.Contents); // ------------------------------------------- // Call method to add client extra information // ------------------------------------------- clientAddRequest.eventClient.clientExtraInformation.FKClientUID = clientAddRequest.eventClient.UID; var cei = RepClientExtraInformation.Insert( HeaderInfo.Instance, clientAddRequest.eventClient.clientExtraInformation, connection); if (cei.ReturnCode != 1) { // Rollback transaction // tr.Dispose(); response.responseStatus = new ResponseStatus(); response.responseStatus = cei; return(response); } // Add user role // SecurityUserRole securityUserRole = new SecurityUserRole(); securityUserRole.FK_Role = FCMConstant.UserRoleType.CLIENT; securityUserRole.FK_UserID = clientAddRequest.headerInfo.UserID; securityUserRole.IsActive = "Y"; securityUserRole.IsVoid = "N"; securityUserRole.StartDate = System.DateTime.Today; securityUserRole.EndDate = Convert.ToDateTime("9999-12-31"); securityUserRole.Add(); // -------------------------------------------- // Add List of Employees // -------------------------------------------- SaveEmployees(clientAddRequest.eventClient.UID, clientAddRequest.eventClient.clientEmployee, clientAddRequest.headerInfo.UserID); // 14/04/2013 // Not adding sets when client is created because the client is created just after the user ID is registered! // // 17/04/2013 // If the ADMINistrator creates the client the document set has to be created and documents added. // if (clientAddRequest.linkInitialSet == "Y") { // -------------------------------------------- // Add first document set // -------------------------------------------- var cds = new ClientDocumentSet(); cds.FKClientUID = newClientUid; // cds.FolderOnly = "CLIENT" + newClientUID.ToString().Trim().PadLeft(4, '0'); cds.FolderOnly = "CLIENT" + newClientUid.ToString().Trim().PadLeft(4, '0'); // cds.Folder = FCMConstant.SYSFOLDER.CLIENTFOLDER + "\\CLIENT" + newClientUID.ToString().Trim().PadLeft(4, '0'); cds.Folder = FCMConstant.SYSFOLDER.CLIENTFOLDER + @"\" + cds.FolderOnly; cds.SourceFolder = FCMConstant.SYSFOLDER.TEMPLATEFOLDER; cds.Add(clientAddRequest.headerInfo, connection); // -------------------------------------------- // Apply initial document set // -------------------------------------------- BUSClientDocument.AssociateDocumentsToClient( clientDocumentSet: cds, documentSetUID: clientAddRequest.eventClient.FKDocumentSetUID, headerInfo: clientAddRequest.headerInfo); // Fix Destination Folder Location // BUSClientDocumentGeneration.UpdateLocation(cds.FKClientUID, cds.ClientSetID); } // Commit transaction tr.Complete(); } } ClientList(clientAddRequest.headerInfo); // List(); // Return new client id response.clientUID = newClientUid; response.responseStatus = new ResponseStatus(); return(response); }
/// <summary> /// Add client /// </summary> /// <param name="headerInfo"> </param> /// <param name="eventClient"></param> /// <param name="linkInitialSet"> </param> /// <returns></returns> public ClientAddResponse ClientAdd(ClientAddRequest clientAddRequest) { var response = new ClientAddResponse(); // This is a new client. // if (string.IsNullOrEmpty(clientAddRequest.eventClient.Name)) { response.responseStatus = new ResponseStatus() { ReturnCode = -0010, ReasonCode = 0001, Message = "Client Name is mandatory." }; return(response); } // -------------------------------------------------------------- // Check if user ID is already connected to a client // -------------------------------------------------------------- #region Check if user is already connected to a client if (!string.IsNullOrEmpty(clientAddRequest.eventClient.FKUserID)) { var checkLinkedUser = new Client(clientAddRequest.headerInfo) { FKUserID = clientAddRequest.eventClient.FKUserID }; //var responseLinked = checkLinkedUser.ReadLinkedUser(); var responseLinked = RepClient.ReadLinkedUser(checkLinkedUser); if (!responseLinked.Successful) { response.responseStatus = new ResponseStatus(); response.responseStatus = responseLinked; return(response); } if (responseLinked.ReturnCode == 0001 && responseLinked.ReasonCode == 0001) { response.responseStatus = new ResponseStatus() { ReturnCode = -0010, ReasonCode = 0002, Message = "User ID is already linked to another client." }; return(response); } } #endregion var newClientUid = 0; using (var connection = new MySqlConnection(ConnString.ConnectionString)) { using (var tr = new TransactionScope(TransactionScopeOption.Required)) { connection.Open(); // ------------------------------- // Call method to add new client // ------------------------------- //var newClient = clientAddRequest.eventClient.Insert(clientAddRequest.headerInfo, connection); var newClient = RepClient.Insert(clientAddRequest.headerInfo, clientAddRequest.eventClient, connection); // var newClientX = eventClient.MySQLInsert(headerInfo); newClientUid = Convert.ToInt32(newClient.Contents); // ------------------------------------------- // Call method to add client extra information // ------------------------------------------- clientAddRequest.eventClient.clientExtraInformation.FKClientUID = clientAddRequest.eventClient.UID; var cei = RepClientExtraInformation.Insert( HeaderInfo.Instance, clientAddRequest.eventClient.clientExtraInformation, connection); if (cei.ReturnCode != 1) { // Rollback transaction // tr.Dispose(); response.responseStatus = new ResponseStatus(); response.responseStatus = cei; return(response); } // -------------------------------------------- // Add first document set // -------------------------------------------- var cds = new ClientDocumentSet(); cds.FKClientUID = newClientUid; // cds.FolderOnly = "CLIENT" + newClientUID.ToString().Trim().PadLeft(4, '0'); cds.FolderOnly = "CLIENT" + newClientUid.ToString().Trim().PadLeft(4, '0'); // cds.Folder = FCMConstant.SYSFOLDER.CLIENTFOLDER + "\\CLIENT" + newClientUID.ToString().Trim().PadLeft(4, '0'); cds.Folder = FCMConstant.SYSFOLDER.CLIENTFOLDER + @"\" + cds.FolderOnly; cds.SourceFolder = FCMConstant.SYSFOLDER.TEMPLATEFOLDER; cds.Add(clientAddRequest.headerInfo, connection); // -------------------------------------------- // Apply initial document set // -------------------------------------------- if (clientAddRequest.linkInitialSet == "Y") { BUSClientDocument.AssociateDocumentsToClient( clientDocumentSet: cds, documentSetUID: clientAddRequest.eventClient.FKDocumentSetUID, headerInfo: clientAddRequest.headerInfo); // Fix Destination Folder Location // BUSClientDocumentGeneration.UpdateLocation(cds.FKClientUID, cds.ClientSetID); } // Commit transaction // tr.Complete(); } } ClientList(clientAddRequest.headerInfo); // List(); // Return new client id response.clientUID = newClientUid; response.responseStatus = new ResponseStatus(); return(response); }