public HttpResponseMessage Register(ClientAddRequest model) { try { if (ModelState.IsValid) { ClientServices svc = new ClientServices(); int? id = svc.Insert(model); ItemResponse <int?> resp = new ItemResponse <int?>(); resp.Item = id; return(Request.CreateResponse(HttpStatusCode.OK, resp)); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); throw; } }
public void Update(ClientAddRequest model) { string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); if (conn.State == System.Data.ConnectionState.Open) { string sqlCmd = "Client_Update"; using (SqlCommand cmd = new SqlCommand(sqlCmd, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter parm = new SqlParameter(); cmd.Parameters.AddWithValue("@Id", model.Id); cmd.Parameters.AddWithValue("@FirstName", model.FirstName); cmd.Parameters.AddWithValue("@LastName", model.LastName); cmd.Parameters.AddWithValue("@Email", model.Email); cmd.Parameters.AddWithValue("@Password", model.Password); cmd.ExecuteNonQuery(); } } } }
public int?Insert(ClientAddRequest model) { string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); if (conn.State == System.Data.ConnectionState.Open) { string sqlCmd = "Client_Insert"; using (SqlCommand cmd = new SqlCommand(sqlCmd, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter parm = new SqlParameter(); parm.SqlDbType = System.Data.SqlDbType.Int; parm.Direction = System.Data.ParameterDirection.Output; parm.ParameterName = "@Id"; cmd.Parameters.Add(parm); cmd.Parameters.AddWithValue("@FirstName", model.FirstName); cmd.Parameters.AddWithValue("@LastName", model.LastName); cmd.Parameters.AddWithValue("@Email", model.Email); cmd.Parameters.AddWithValue("@Password", model.Password); cmd.ExecuteNonQuery(); int id = (int)cmd.Parameters["@Id"].Value; return(id); } } else { return(null); } } }
/// <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); }
public ClientAddResponse ClientAdd(ClientAddRequest clientAddRequest) { var response = new BUSClient().ClientAdd(clientAddRequest); return(response); }
/// <summary> /// Add/ Update client /// </summary> /// <param name="client"></param> public void SaveClient() { if (cbxAssociateInitialSet.Checked) { if (comboContractorSize.SelectedIndex < 0) { MessageBox.Show("Please select contractor size."); return; } } // Check if the client is new. // If the UID is empty, it is a new client. // If the UID is populated, it is an existing client. // if (string.IsNullOrEmpty(txtUID.Text)) { _client.UID = 0; } else { _client.UID = Convert.ToInt32(txtUID.Text); } _client.ABN = txtABN.Text; _client.Name = txtName.Text; _client.LegalName = txtLegalName.Text; _client.Address = txtAddress.Text; _client.Phone = txtPhone.Text; _client.Fax = txtFax.Text; _client.Mobile = txtMobile.Text; _client.Logo1Location = txtLogo1Location.Text; _client.Logo2Location = ""; _client.Logo3Location = ""; _client.EmailAddress = txtEmailAddress.Text; _client.MainContactPersonName = txtContactPerson.Text; _client.FKUserID = comboUserID.Text; _client.DocSetUIDDisplay = comboContractorSize.Text; _client.DisplayLogo = checkDisplayLogo.Checked ? 'Y' : 'N'; if (string.IsNullOrEmpty(_client.DocSetUIDDisplay)) { _client.FKDocumentSetUID = 0; } else { string[] part = _client.DocSetUIDDisplay.Split(';'); _client.FKDocumentSetUID = Convert.ToInt32(part[0]); } _client.DisplayLogo = checkDisplayLogo.Checked ? 'Y' : 'N'; _client.clientExtraInformation = new ClientExtraInformation(); _client.clientExtraInformation.FKClientUID = _client.UID; _client.clientExtraInformation.DateToEnterOnPolicies = dtpDateToEnterOnPolicies.Value; _client.clientExtraInformation.ActionPlanDate = dtpActionPlanDate.Value; _client.clientExtraInformation.CertificationTargetDate = dtpCertificationTargetDate.Value; _client.clientExtraInformation.ScopeOfServices = txtScopeOfServices.Text; _client.clientExtraInformation.TimeTrading = txtTimeTrading.Text; _client.clientExtraInformation.RegionsOfOperation = txtRegionsOfOperation.Text; _client.clientExtraInformation.OperationalMeetingsFrequency = txtOperationalMeetings.Text; _client.clientExtraInformation.ProjectMeetingsFrequency = txtProjectMeetings.Text; // Check if it is to add / update if (_client.UID <= 0) { string associateInitialSet = "N"; if (cbxAssociateInitialSet.Checked) { associateInitialSet = "Y"; } var clientAddRequest = new ClientAddRequest(); clientAddRequest.headerInfo = HeaderInfo.Instance; clientAddRequest.eventClient = _client; clientAddRequest.linkInitialSet = associateInitialSet; // var response = new BUSClient().ClientAdd(clientAddRequest); var response = ClientAdd(clientAddRequest); ControllerUtils.ShowFCMMessage(response.responseStatus, Utils.UserID); _client.UID = 0; if (response.responseStatus.Successful) { _client.UID = response.clientUID; txtUID.Text = _client.UID.ToString(); txtRecordVersion.Text = _client.RecordVersion.ToString(); } } else { var requestClientUpdate = new ClientUpdateRequest(); requestClientUpdate.headerInfo = HeaderInfo.Instance; requestClientUpdate.eventClient = _client; // var response = new BUSClient().ClientUpdate(requestClientUpdate); var response = ClientUpdate(requestClientUpdate); txtRecordVersion.Text = _client.RecordVersion.ToString(CultureInfo.InvariantCulture); ControllerUtils.ShowFCMMessage(response.response, Utils.UserID); } // Refresh client list // Utils.ClientID = _client.UID; var responseClientList = new BUSClient().ClientList(HeaderInfo.Instance); Utils.ClientList = responseClientList.clientList; }