Ejemplo n.º 1
0
        private bool IfNotExists(InspectionCenter inspectionCenter)
        {
            var inspectionCenterResult = _centerRepository.CheckIfAlreadyExists(inspectionCenter);

            if (inspectionCenterResult == null)
            {
                return(true);
            }
            throw new ServiceBaseException(_l["Cannot repeat inspection center with the same name"], 1000);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add Inspection Center Coverage
        /// </summary>
        private void AddCoverage(InspectionCenter inspectionCenter, JToken item, Dictionary <string, object> customProperties)
        {
            var inspectionCenterCoverageItem = item.ToObject <InspectionCenterCoverage>();

            // Check IF District Already Assigned to Another Inspection Center
            //IsOtherCoverageExists(inspectionCenter, inspectionCenterCoverageItem);
            inspectionCenterCoverageItem.InspectionCenterId = inspectionCenter.Id;
            inspectionCenterCoverageItem.CreationTime       = DateTime.Now;
            _coverageRepository.Add(inspectionCenterCoverageItem, customProperties);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add Role Emails
        /// </summary>
        private void AddRoleEmails(InspectionCenter inspectionCenter, JToken item, Dictionary <string, object> customProperties)
        {
            var groupEmailsItem = item.ToObject <RoleEmails>();

            groupEmailsItem.Id = Guid.NewGuid();
            groupEmailsItem.InspectionCenterId = inspectionCenter.Id;
            groupEmailsItem.CreationTime       = DateTime.Now;

            _roleEmailsRepository.Add(groupEmailsItem, customProperties);
        }
Ejemplo n.º 4
0
 private void ValidateInputPattern(InspectionCenter inspectionCenter)
 {
     if (string.IsNullOrWhiteSpace(inspectionCenter.Name) || !Regex.IsMatch(inspectionCenter.Name, @"^[ء-يa-zA-Z0-9-&-_@ ]{1,150}$"))
     {
         throw new ServiceBaseException(_l["Enter valid value for Center name"], 020);
     }
     if (string.IsNullOrWhiteSpace(inspectionCenter.RefCode) || !Regex.IsMatch(inspectionCenter.RefCode, @"^[a-zA-Z0-9]{1,150}$"))
     {
         throw new ServiceBaseException(_l["Enter valid value for RefCode"], 020);
     }
 }
Ejemplo n.º 5
0
        private void IsOtherCoverageExists(InspectionCenter center, List <InspectionCenterCoverage> coverage)
        {
            var containsDuplicateDistrict = coverage.Select(x => x.DistrictId).Distinct().Count() < coverage.Count();

            if (containsDuplicateDistrict)
            {
                throw new ServiceBaseException(_l["selected coverage area repeated with another center or within the same center"], 1000);
            }
            // This needs to be finalized as how we can check if the coverage is covered by another inspection center if this is in same table.
            var otherCoverage = GetAllCoverageExceptCurrent(center.Id);

            //if (otherCoverage.Exists(_cov => _cov.CityId == coverage.CityId && _cov.DistrictId == coverage.DistrictId) ||
            //    otherCoverage.Exists(_cov => _cov.CityId == coverage.CityId && _cov.DistrictId == InspectionCenterConstants.AllDistrict))
            //{
            //    throw new ServiceBaseException(_l["Inspection region covered by another inspection center"], 1000);
            //}
        }
Ejemplo n.º 6
0
        public bool Create(InspectionCenter inspectionCenter, string requestBody)
        {
            ValidateInputPattern(inspectionCenter);
            // Check IF Inspection Center Already Present
            IfNotExists(inspectionCenter);

            // Dyanmic Custom Controls
            var customProperties = GetCustomProperties(requestBody, InspectionCenterConstants.InspectionCenterEntity);

            //var inspectionCenterCoverageToken = GetInspectionCoverages(requestBody);
            //var inspectionCenterCoverageItem = inspectionCenterCoverageToken.Children().FirstOrDefault();
            //var centerCoverageCustomProperties = GetCustomProperties(inspectionCenterCoverageItem.ToString(),
            //    InspectionCenterConstants.InspectionCenterCoverageEntity);

            //var roleEmailsToken = GetRoleEmails(requestBody);

            //RoleEmail Custom Property
            //var roleEmailCustomProperties =
            //    GetCustomProperties(roleEmailsToken.Children().FirstOrDefault().ToString(),
            //        InspectionCenterConstants.RoleEmailsEntity);

            using (TransactionScope scope = new TransactionScope())
            {
                inspectionCenter.Id           = Guid.NewGuid();
                inspectionCenter.CreationTime = DateTime.Now;
                // inspectionCenter.RoleEmails = inspectionCenter.RoleEmails.ToString();
                _centerRepository.Add(inspectionCenter, customProperties);

                //foreach (var item in inspectionCenterCoverageToken.Children())
                //{
                //    AddCoverage(inspectionCenter, item, centerCoverageCustomProperties);
                //}

                // Role Emails
                //AddRoleEmailsList(inspectionCenter, requestBody,roleEmailCustomProperties);

                _messageQueueManager.SendUpdateCenter(_messagePublisherConfigSettings.CenterUpdatedExchange, new UpdatedCenter {
                    CenterId = inspectionCenter.Id
                });

                scope.Complete();
            }
            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Add Role Emails List
        /// </summary>
        private void AddRoleEmailsList(InspectionCenter inspectionCenter, string requestBody, Dictionary <string, object> roleEmailCustomProperties)
        {
            var groupEmailsToken = GetRoleEmails(requestBody);

            // Get DB update Role Emails
            //dbRoleEmails.CopyTo(dbUpdateRoleEmails);

            foreach (var item in groupEmailsToken.Children())
            {
                var groupEmails = item.ToObject <RoleEmails>();

                //check exists role with new email
                if (groupEmailsToken.Children().Values("role").Where(role => role.ToString() == groupEmails.Role).Count() > 1)
                {
                    throw new ServiceBaseException(_l["Cannot repeat role inside inspection center:"], 1000);
                }

                AddRoleEmails(inspectionCenter, item, roleEmailCustomProperties);
            }
        }
Ejemplo n.º 8
0
        public bool Update(InspectionCenter inspectionCenter, string requestBody)
        {
            ValidateInputPattern(inspectionCenter);

            // Check IF Inspection Center Already Present
            if (!IfNotExists(inspectionCenter))
            {
                throw new ServiceBaseException(_l[InspectionCenterConstants.NO_DATA_FOUND]);
            }

            // Dyanmic Custom Controls
            var centerCustomProperties = GetCustomProperties(requestBody, InspectionCenterConstants.InspectionCenterEntity);

            var dbInspectionCenterCoverage = GetCoverageByCenterID(inspectionCenter.Id);

            var centerCoverageList = CustomSchemaHelper <List <InspectionCenterCoverage> > .Deserialize(inspectionCenter.InspectionCenterCoverages);

            var roleEmailList = CustomSchemaHelper <List <RoleEmails> > .Deserialize(inspectionCenter.RoleEmails);

            IsOtherCoverageExists(inspectionCenter, centerCoverageList);

            if (roleEmailList.Select(x => x.Role).Distinct().Count() < roleEmailList.Count())
            {
                throw new ServiceBaseException(_l["Cannot repeat role inside inspection center:"], 1000);
            }
            using (TransactionScope scope = new TransactionScope())
            {
                inspectionCenter.LastModificationTime = DateTime.Now;
                _centerRepository.Update(inspectionCenter, centerCustomProperties);
                _messageQueueManager.SendUpdateCenter(_messagePublisherConfigSettings.CenterUpdatedExchange, new UpdatedCenter {
                    CenterId = inspectionCenter.Id
                });

                scope.Complete();
            }
            return(true);
        }