Ejemplo n.º 1
0
        //[Authorize(Roles = "UpdateCustomer")]
        public async Task <ObjectResult> Put(string id, [FromBody] WebControlViewModel webControlViewModel)
        {
            GenericResult rs = new GenericResult();

            //DEFACEWEBSITEContext context = new DEFACEWEBSITEContext();
            try
            {
                string command = $"dbo.CW_WEB_CONTROL_Upd @p_PROJECT_ID = '{webControlViewModel.CwWebControl.PROJECT_ID}', @p_OPERATION_STATE = '{webControlViewModel.CwWebControl.OPERATION_STATE}',@p_RECORD_STATUS='1',@p_AUTH_STATUS='U',@p_MAKER_ID='{webControlViewModel.CwWebControl.MAKER_ID}',@p_CREATE_DT='{webControlViewModel.CwWebControl.CREATE_DT}',@p_EDITOR_ID='{webControlViewModel.CwWebControl.EDITOR_ID}',@p_EDIT_DT='{DateTime.Now.Date}', @p_NOTES = '{webControlViewModel.CwWebControl.NOTES}'";
                //string command = $"dbo.CMS_CUSTOMER_MASTER_Upd @p_CUSTOMER_CODE='{customer.CustomerCode}',@p_CUSTOMER_NAME='{customer.CustomerName}',@p_COMPANY_NAME='{customer.CompanyName}',@p_ADDRESS='{customer.Address}',@p_TAX_CODE='{customer.TaxCode}',@p_Email='{customer.Email}',@p_PhoneNumber='{customer.PhoneNumber}',@p_RECORD_STATUS='1',@p_AUTH_STATUS='U',@p_MAKER_ID='{customer.MakerId}',@p_CREATE_DT='{customer.CreateDt}',@p_EDITOR_ID='{customer.EditorId}',@p_EDIT_DT='{DateTime.Now.Date}'";
                var result = await _context.Database.ExecuteSqlCommandAsync(command, cancellationToken : CancellationToken.None);

                if (result > 0)
                {
                    rs.Succeeded = true;
                    rs.Message   = "Cập nhật trạng thái Website thành công";
                }
                else
                {
                    rs.Succeeded = false;
                    rs.Message   = "Đã có lỗi xảy ra";
                }
                ObjectResult objRes = new ObjectResult(rs);
                //context.Dispose();
                return(objRes);
            }
            catch (Exception ex)
            {
                rs.Succeeded = false;
                rs.Message   = ex.Message;
                ObjectResult objRes = new ObjectResult(rs);
                //context.Dispose();
                return(objRes);
            }
        }
Ejemplo n.º 2
0
        // [Authorize(Roles = "ViewProduct")]
        //[Authorize(Roles ="GetSearchProduct")]
        public async Task <IActionResult> Get(int?page, int?pageSize, string searchstring = null)
        {
            PaginationSet <WebControlViewModel> pagedSet = new PaginationSet <WebControlViewModel>();

            var result =
                _context.PrjProjectMaster.FromSql("dbo.PRJ_PROJECT_MASTER_Search @p_TOP=''");

            int currentPage     = page.Value;
            int currentPageSize = pageSize.Value;

            if (!String.IsNullOrEmpty(searchstring))
            {
                result = result.Where(prj => prj.PROJECT_CODE.ToLower().Contains(searchstring) ||
                                      prj.PROJECT_NAME.ToLower().Contains(searchstring) ||
                                      prj.SUB_DOMAIN.ToLower().Contains(searchstring.ToLower()) ||
                                      prj.DOMAIN.ToLower().Contains(searchstring.ToLower()));
            }

            var totalRecord = result.Count();
            var totalPages  = (int)Math.Ceiling((double)totalRecord / pageSize.Value);


            var webControlResult = _context.CwWebControls.FromSql("dbo.CW_WEB_CONTROL_Search @p_TOP=''").ToList();

            List <WebControlViewModel> listWebControlViewModel = new List <WebControlViewModel>();
            List <PrjProjectMaster>    listProject             = result.ToList();

            foreach (var item in listProject)
            {
                WebControlViewModel newItem = new WebControlViewModel();
                newItem.PrjProjectMaster = item;
                newItem.CwWebControl     = webControlResult.SingleOrDefault(wc => wc.PROJECT_ID.Equals(item.PROJECT_ID));
                if (newItem.CwWebControl == null)
                {
                    newItem.CwWebControl = new CwWebControl();
                    newItem.CwWebControl.OPERATION_STATE = "1";
                    newItem.CwWebControl.OPERATION_NAME  = "Đang hoạt động";
                }
                listWebControlViewModel.Add(newItem);
            }


            var messages = listWebControlViewModel.Skip((currentPage) * currentPageSize).Take(currentPageSize).ToList();

            Response.AddPagination(currentPage, currentPageSize, totalRecord, totalPages);

            pagedSet = new PaginationSet <WebControlViewModel>()
            {
                Page       = currentPage,
                TotalCount = totalRecord,
                TotalPages = totalPages,
                Items      = messages
            };

            return(new ObjectResult(pagedSet));
        }
Ejemplo n.º 3
0
        public async Task <Data.ObjectResult> Post([FromBody] WebControlViewModel webControlViewModel)
        {
            HttpClient apiClient = new HttpClient();
            IEnumerable <CmAllcode> listMySqlConn;

            try
            {
                Uri    address    = new Uri("http://103.7.41.51:9823/api/AllCode/MYSQL_CONN");
                string jsonString = await apiClient.GetStringAsync(address);

                listMySqlConn = JsonConvert.DeserializeObject <IEnumerable <CmAllcode> >(jsonString);
            }
            catch (Exception ex)
            {
                listMySqlConn = null;
                Data.ObjectResult result = new Data.ObjectResult();
                result.isSucceeded  = false;
                result.ErrorMessage = "Lỗi trong quá trình tạo kết nối đến MySQL - " + ex.Message;
                return(result);
            }
            finally
            {
                apiClient.Dispose();
            }
            using (var client = new SshClient("103.7.41.51", "root", "Gsoft@235"))
            {
                try
                {
                    client.Connect();
                    if (client.IsConnected)
                    {
                        var portForwarded = new ForwardedPortLocal("127.0.0.1", 0, "127.0.0.1", 3306);
                        client.AddForwardedPort(portForwarded);
                        portForwarded.Start();
                        string mySQLConnectionString = "";
                        if (listMySqlConn != null)
                        {
                            mySQLConnectionString = listMySqlConn.ToList()[0].Content;
                        }
                        DatabaseConnect mySqlConnector = new DatabaseConnect(mySQLConnectionString);

                        Data.ObjectResult result = new Data.ObjectResult();
                        result = mySqlConnector.OpenConnection();
                        if (result.isSucceeded == false)
                        {
                            mySqlConnector.CloseConnection();
                            return(result);
                        }
                        string useDatabase = $"USE {webControlViewModel.PrjProjectMaster.DATABASE_NAME};";
                        result = await mySqlConnector.ExecuteCommand(useDatabase);

                        if (result.isSucceeded == false)
                        {
                            mySqlConnector.CloseConnection();
                            return(result);
                        }
                        string warningPage = "http://warning.gwebsite.net";
                        //HttpClient getWarningClient = new HttpClient();
                        //IEnumerable<CmAllcode> warningURL = null;
                        //try
                        //{
                        //    Uri address = new Uri("http://103.7.41.51:9823/api/AllCode/WARNING_URL");
                        //    string jsonString = await apiClient.GetStringAsync(address);
                        //    warningURL = JsonConvert.DeserializeObject<IEnumerable<CmAllcode>>(jsonString);
                        //    if (warningURL != null)
                        //    {
                        //        warningPage = warningURL.ToList()[0].Content;
                        //    }
                        //}
                        //catch (Exception ex)
                        //{

                        //    result = new Data.ObjectResult();
                        //    result.isSucceeded = false;
                        //    result.ErrorMessage = "Lỗi trong quá trình lấy dữ liệu - " + ex.Message;
                        //    return result;
                        //}
                        //finally
                        //{
                        //    getWarningClient.Dispose();
                        //    warningURL = null;
                        //}
                        string siteURL = "";
                        //OPERATION_STATE = 1 nghia la Website dang hoat dong (kiem tra bang CM_ALLCODE)
                        if (webControlViewModel.CwWebControl.OPERATION_STATE.Equals("1"))
                        {
                            siteURL = "http://" + webControlViewModel.PrjProjectMaster.SUB_DOMAIN + "." + webControlViewModel.PrjProjectMaster.DOMAIN;
                        }
                        //OPERATION_STATE = 0 nghia la Website tam dung hoat dong, redirect ve trang warning.gwebsite.net (kiem tra bang CM_ALLCODE)
                        else if (webControlViewModel.CwWebControl.OPERATION_STATE.Equals("0"))
                        {
                            siteURL = warningPage;
                        }
                        string updateSiteURLQuery = $"Update wp_options SET option_value = '{siteURL}' WHERE option_name = 'siteurl'";
                        result = await mySqlConnector.ExecuteCommand(updateSiteURLQuery);

                        if (result.isSucceeded == false)
                        {
                            mySqlConnector.CloseConnection();
                            return(result);
                        }
                        string updateHomeQuery = $"Update wp_options SET option_value = '{siteURL}' WHERE option_name = 'home'";
                        result = await mySqlConnector.ExecuteCommand(updateHomeQuery);

                        if (result.isSucceeded == false)
                        {
                            mySqlConnector.CloseConnection();
                            return(result);
                        }

                        mySqlConnector.CloseConnection();
                        result.isSucceeded  = true;
                        result.ErrorMessage = $"Chuyển trạng thái hoạt động của website {webControlViewModel.PrjProjectMaster.SUB_DOMAIN + "." + webControlViewModel.PrjProjectMaster.DOMAIN} thành công";
                        return(result);
                    }
                    else
                    {
                        Data.ObjectResult result = new Data.ObjectResult();
                        result.isSucceeded  = false;
                        result.ErrorMessage = "Lỗi kết nối SSH";
                        return(result);
                    }
                }
                catch (Exception ex)
                {
                    Data.ObjectResult rs = new Data.ObjectResult();
                    rs.isSucceeded  = false;
                    rs.ErrorMessage = "Lỗi - " + ex.Message;
                    return(rs);
                }
            }
        }