예제 #1
0
        /// <summary>
        /// Validate dữ liệu riêng từng đối tượng
        /// </summary>
        /// <param name="entity">đối tượng cần validate</param>
        /// <param name="http">Phương thức POST hay PUT</param>
        /// Created By: NXCHIEN 07/05/2021
        protected override void CustomValidate(Employee entity, HTTPType http)
        {
            // Check trùng mã code
            // Khởi tạo giá trị
            var employeeCode   = entity.EmployeeCode;
            var employeeId     = entity.EmployeeId;
            var checkCodeExist = _employeeRepository.CheckEmployeeAttributeExist(Properties.AttributeResource.EmployeeCode, employeeId, http, employeeCode);

            // Kiểm tra trùng hay không
            if (checkCodeExist)
            {
                throw new EmployeeExceptions(Properties.Resources.Msg_Code_Exist);
            }


            //Check trùng IDentifyNumber
            // Khởi tạo giá trị
            var identifyNumber           = entity.IdentifyNumber;
            var checkIdentifyNumberExist = _employeeRepository.CheckEmployeeAttributeExist(Properties.AttributeResource.IdentifyNumber, employeeId, http, identifyNumber);

            // Kiểm tra trùng hay không
            if (checkIdentifyNumberExist)
            {
                throw new EmployeeExceptions(Properties.Resources.Msg_IdentifyNumber_Exist);
            }

            // Check trùng số điện thoại
            // Khởi tạo giá trị
            var phoneNumber           = entity.PhoneNumber;
            var checkphoneNumberExist = _employeeRepository.CheckEmployeeAttributeExist(Properties.AttributeResource.PhoneNumber, employeeId, http, phoneNumber);

            // Kiểm tra trùng hay không
            if (checkphoneNumberExist)
            {
                throw new EmployeeExceptions(Properties.Resources.Msg_Phone_Exist);
            }

            //Check trùng Email
            var email           = entity.Email;
            var checkEmailExist = _employeeRepository.CheckEmployeeAttributeExist(Properties.AttributeResource.Email, employeeId, http, email);

            if (checkEmailExist)
            {
                throw new EmployeeExceptions(Properties.Resources.Msg_Email_Exist);
            }
        }
예제 #2
0
 /// <summary>
 /// Kiểm tra trùng attribute của đối tượng nhân viên
 /// </summary>
 /// <param name="employeeCode">Mã code nhân viên</param>
 /// <param name="employeeId">Mã ID nhân viên</param>
 /// <param name="http">Phương thứ PUT hay POST</param>
 /// <param name="attributeValue">Giá trị của attribute</param>
 /// <returns>TRUE hoặc FALSE</returns>
 /// Created By: NXCHIEN 07/05/2021
 public bool CheckEmployeeAttributeExist(string attribute, Guid?employeeId, HTTPType http, string attributeValue)
 {
     using (dbConnection = new MySqlConnection(connectionDb))
     {
         DynamicParameters parameters = new DynamicParameters();
         if (http == HTTPType.POST)
         {
             parameters.Add($"@{attribute}", attributeValue);
             parameters.Add("@employeeId", null);
         }
         else if (http == HTTPType.PUT)
         {
             parameters.Add($"@{attribute}", attributeValue);
             parameters.Add("@employeeId", employeeId);
         }
         var sqlCommand = $"Proc_Check{attribute}Exist";
         var check      = dbConnection.QueryFirstOrDefault <bool>(sqlCommand, parameters, commandType: CommandType.StoredProcedure);
         return(check);
     }
 }
예제 #3
0
        /// <summary>
        /// Validate dữ liệu riêng tường đối tượng.
        /// </summary>
        /// <param name="customer">đối tượng truyền vào.</param>
        /// <param name="http">Phương thức Post or PUT.</param>
        /// CreatedBy: NXChien (28/04/2021)
        protected override void CustomValidate(Customer customer, HTTPType http)
        {
            // Khởi tạo giá trị và gán giá trị
            var customerCode = customer.CustomerCode;
            var customerId   = customer.CustomerId;
            var phoneNumber  = customer.PhoneNumber;
            // Kiểm tra Mã code khách hàng đã tồn tại hay chưa
            var IsCheckHttpPostOrPut = _customerRepository.CheckCustomerCodeExist(customerCode, customerId, http);

            if (IsCheckHttpPostOrPut == true)
            {
                throw new CustomExceptions(Properties.Resources.Msg_Code_Exist);
            }

            //TODO: Chưa check PhoneNumber theo dạng PUT OR POST
            var phone = _customerRepository.CheckPhoneNumberExist(phoneNumber);

            if (phone)
            {
                throw new CustomExceptions(Properties.Resources.Msg_Phone_Exist);
            }
        }
예제 #4
0
 /// <summary>
 /// Check CustomerCode đã tồn tại hay chưa.
 /// </summary>
 /// <param name="customerCode">Mã khách hàng.</param>
 /// <param name="customerId">The customerId<see cref="Guid"/>.</param>
 /// <param name="http">The http<see cref="HTTPType"/>.</param>
 /// <returns>true or false.</returns>
 /// CreatedBy: NXChien (28/04/2021)
 public bool CheckCustomerCodeExist(string customerCode, Guid customerId, HTTPType http)
 {
     using (dbConnection = new MySqlConnection(connectionString))
     {
         var sqlCommandDuplicate      = "";
         DynamicParameters parameters = new DynamicParameters();
         if (http == HTTPType.POST) // post
         {
             sqlCommandDuplicate = "Proc_CheckCustomerCodeExists";
             parameters.Add("@m_CustomerCode", customerCode);
         }
         else if (http == HTTPType.PUT)  //put
         {
             sqlCommandDuplicate = "Proc_H_CheckCustomerCodeExists";
             parameters.Add("@customerCode", customerCode);
             parameters.Add("@customerId", customerId);
         }
         var check = dbConnection.QueryFirstOrDefault <bool>
                         (sqlCommandDuplicate, param: parameters, commandType: CommandType.StoredProcedure);
         return(check);
     }
 }
예제 #5
0
        public SocialHttp(ModuleSettings settings, string url, HTTPParams parameters, HTTPType httpType, System.Action <string, bool> onCompleted)
        {
                        #if USE_WWW
            if (httpType == HTTPType.Post)
            {
                var form = new WWWForm();
                foreach (var param in parameters.items)
                {
                    form.AddField(param.key, param.GetValue(settings));
                }

                this.www = new WWW(url, form);
            }
            else if (httpType == HTTPType.Get)
            {
                foreach (var param in parameters.items)
                {
                    url = url.Replace("{" + param.key + "}", param.GetValue(settings));
                }

                this.www = new WWW(url);
            }

            SocialSystem.WaitFor(this.Wait(() => {
                if (string.IsNullOrEmpty(this.www.error) == false)
                {
                    Debug.LogError(this.www.error);

                    // error
                    onCompleted(this.www.error, false);
                }
                else
                {
                    // success
                    onCompleted(this.www.text, true);
                }
            }));
                        #else
            if (httpType == HTTPType.Post)
            {
                var form = new WWWForm();
                foreach (var param in parameters.items)
                {
                    form.AddField(param.key, param.GetValue(settings));
                }

                this.www = new WWW(url, form);
            }
            else if (httpType == HTTPType.Get)
            {
                foreach (var param in parameters.items)
                {
                    url = url.Replace("{" + param.key + "}", param.GetValue(settings));
                }

                ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(delegate { return(true); });

                var uri = new Uri(url.Trim() + "/");                    // I don't know about last `/` but it works only with it ;(

                WebRequest request = WebRequest.Create(uri);
                // If required by the server, set the credentials.
                request.Credentials = CredentialCache.DefaultCredentials;
                // Get the response.
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                // Get the stream containing content returned by the server.
                Stream dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                string responseFromServer = reader.ReadToEnd();

                // Cleanup the streams and the response.
                reader.Close();
                dataStream.Close();
                response.Close();

                onCompleted(responseFromServer, response.StatusCode == HttpStatusCode.OK);
            }
                        #endif

            Debug.Log(url);
        }
예제 #6
0
        /// <summary>
        /// Validate dữ liệu dùng chung.
        /// </summary>
        /// <param name="entity">đối tượng truyền vào.</param>
        /// <param name="http">Phương thức POST or PUT.</param>
        /// CreatedBy: NXChien (28/04/2021)
        private void Validate(MISAEntity entity, HTTPType http)
        {
            // Lấy ra tất cả property của đối tượng
            var properties = typeof(MISAEntity).GetProperties();

            foreach (var property in properties)
            {
                // Lấy ra attribute của đối tượng
                var requiredAttribute = property.GetCustomAttributes(typeof(MISARequired), true);
                if (requiredAttribute.Length > 0)
                {
                    // Lấy ra giá trị của property
                    var propertyValue = property.GetValue(entity);
                    // Kiểm tra nếu giá trị null thì gán thành empty.
                    if (propertyValue == null || string.IsNullOrEmpty(propertyValue.ToString()))
                    {
                        // Lấy ra message lỗi của attribute.
                        var msgError = (requiredAttribute[0] as MISARequired).MsgError;
                        if (string.IsNullOrEmpty(msgError))
                        {
                            msgError = $"{property.Name} không được phép để trống!";
                        }
                        throw new CustomExceptions(msgError);
                    }
                }
                // Kiểm tra độ dài mã Code của property
                var maxLengthAttribute = property.GetCustomAttributes(typeof(MISAMaxLength), true);
                if (maxLengthAttribute.Length > 0)
                {
                    // Lấy ra giá trị của property
                    var propertyValue = property.GetValue(entity);
                    // Lấy ra giá trị truyền vào của MISAMaxLength
                    var maxLength = (maxLengthAttribute[0] as MISAMaxLength).MaxLength;
                    // Kiểm tra độ dài
                    if (propertyValue.ToString().Length > maxLength)
                    {
                        var msgError = (maxLengthAttribute[0] as MISAMaxLength).MsgError_MaxLength;
                        if (string.IsNullOrEmpty(msgError))
                        {
                            msgError = $"Độ dài của {property.Name} phải nhỏ hơn {maxLength}";
                        }
                        throw new CustomExceptions(msgError);
                    }
                }
                // Kiểm tra email
                var emailAttribute = property.GetCustomAttributes(typeof(MISAEmail), true);
                if (emailAttribute.Length > 0)
                {
                    // Lấy giá trị email
                    var emailValue = property.GetValue(entity);
                    // Khởi tạo regex và kiểm tra
                    Regex regex = new Regex(Properties.Resources.Regex_String);
                    if (!regex.IsMatch(emailValue.ToString()))
                    {
                        var msgErrorEmail = (emailAttribute[0] as MISAEmail).MsgErrorEmail;
                        if (string.IsNullOrEmpty(msgErrorEmail.ToString()))
                        {
                            msgErrorEmail = $"{property.Name} không đúng định dạng!";
                        }
                        throw new CustomExceptions(msgErrorEmail);
                    }
                }

                /// Kiểm tra số điện thoại
                ///var phoneAttribute = property.GetCustomAttributes(typeof(MISAPhone), true);
                ///if (phoneAttribute.Length > 0)
                ///{
                ///    var phoneValue = property.GetValue(entity);
                ///    if (!int.TryParse(phoneValue.ToString(), out int n))
                ///    {
                ///        var msgErrorPhone = (phoneAttribute[0] as MISAPhone).MsgErrorPhone;
                ///        if (string.IsNullOrEmpty(msgErrorPhone))
                ///        {
                ///            msgErrorPhone = $"{property.Name} phải là số!";
                ///        }
                ///        throw new CustomExceptions(msgErrorPhone);
                ///    }
                ///}
            }

            //TODO: Check động chưa dùng đến vì customerGroup chưa cần check trùng.
            ///Check trùng mã đối tượng -- Check động :
            ///var entityCode = typeof(MISAEntity).GetProperty($"{tableName}Code").GetValue(entity);
            ///var entityId = typeof(MISAEntity).GetProperty($"{tableName}Id").GetValue(entity);
            ///var IsCheckHttpPostOrPut = _baseRepository.CheckEntityCodeExist(entityCode.ToString(), Guid.Parse(entityId.ToString()), http);
            ///if (IsCheckHttpPostOrPut == true)
            ///{
            ///throw new CustomExceptions("Mã khách hàng đã tồn tại trên hệ thống!");
            ///}

            // Validate dữ liệu riêng tường đối tượng
            CustomValidate(entity, http);
        }
예제 #7
0
 /// <summary>
 /// Validate dữ liệu riêng tường đối tượng.
 /// </summary>
 /// <param name="entity">đối tượng truyền vào.</param>
 /// <param name="http">Phương thức POST or PUT.</param>
 /// CreatedBy: NXChien (28/04/2021)
 protected virtual void CustomValidate(MISAEntity entity, HTTPType http)
 {
 }
예제 #8
0

        
예제 #9
0
			public GetEnumerator(HTTPType par) 
			{
                this.SetSamplerState(0, SamplerStateparent = par;
                this.SetSamplerState(0, SamplerStatenIndex = -1;
			}
예제 #10
0
		public SocialHttp(ModuleSettings settings, string url, HTTPParams parameters, HTTPType httpType, System.Action<string, bool> onCompleted) {

			#if USE_WWW
			if (httpType == HTTPType.Post) {

				var form = new WWWForm();
				foreach (var param in parameters.items) {

					form.AddField(param.key, param.GetValue(settings));

				}

				this.www = new WWW(url, form);

			} else if (httpType == HTTPType.Get) {

				foreach (var param in parameters.items) {

					url = url.Replace("{" + param.key + "}", param.GetValue(settings));

				}
				
				this.www = new WWW(url);

			}

			SocialSystem.WaitFor(this.Wait(() => {

				if (string.IsNullOrEmpty(this.www.error) == false) {
					
					Debug.LogError(this.www.error);

					// error
					onCompleted(this.www.error, false);

				} else {

					// success
					onCompleted(this.www.text, true);

				}

			}));
			#else
			if (httpType == HTTPType.Post) {
				
				var form = new WWWForm();
				foreach (var param in parameters.items) {
					
					form.AddField(param.key, param.GetValue(settings));
					
				}
				
				this.www = new WWW(url, form);
				
			} else if (httpType == HTTPType.Get) {
				
				foreach (var param in parameters.items) {
					
					url = url.Replace("{" + param.key + "}", param.GetValue(settings));
					
				}

				ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(delegate { return true; });

				var uri = new Uri(url.Trim() + "/");	// I don't know about last `/` but it works only with it ;(

				WebRequest request = WebRequest.Create (uri);
				// If required by the server, set the credentials.
				request.Credentials = CredentialCache.DefaultCredentials;
				// Get the response.
				HttpWebResponse response = (HttpWebResponse)request.GetResponse ();

				// Get the stream containing content returned by the server.
				Stream dataStream = response.GetResponseStream ();
				// Open the stream using a StreamReader for easy access.
				StreamReader reader = new StreamReader (dataStream);
				// Read the content.
				string responseFromServer = reader.ReadToEnd ();

				// Cleanup the streams and the response.
				reader.Close ();
				dataStream.Close ();
				response.Close ();
				
				onCompleted(responseFromServer, response.StatusCode == HttpStatusCode.OK);

			}
			#endif
			
			Debug.Log(url);

		}
예제 #11
0
 public ActionBase(string name, string uri, HTTPType type)
 {
     ActionName = name;
     ActionURI  = uri;
     ActionType = type;
 }