Exemplo n.º 1
0
        public async Task <int> GetPhotos(string nationalId)
        {
            CriteriaBuilder builder = new CriteriaBuilder();

            builder.Add("CustomerIdentifier", nationalId);
            builder.Add("PhotoUploadStatus", 1);
            List <CustomerPhoto> photos = await GetManyByCriteria(builder);

            return(photos.Count);
        }
Exemplo n.º 2
0
        protected async Task <SaveResponse <T> > OverwriteAsync(T model, string field)
        {
            try
            {
                PropertyInfo propertyInfo = model.GetType().GetRuntimeProperty(field);
                if (propertyInfo == null)
                {
                    throw new Exception("Unknown field '" + field + "' specified in Overwrite property method of '" + this.GetType().FullName + "' or a base class in its inheritance hierarchy.");
                }

                if (!propertyInfo.CanRead)
                {
                    throw new Exception("Property '~' specified in Overwrite method of class '~' or one of its base classes is write-only, cannot generate filter based on it.".GetFormated(field, this.GetType()));
                }

                object value = propertyInfo.GetValue(model);

                CriteriaBuilder criteriaBuilder = new CriteriaBuilder();

                var result = await this.OverwriteAsync(model, criteriaBuilder.Add(field, value));

                this.Logger.Debug("Returning id " + result.SavedModel.Id);

                return(result);
            }
            catch (Exception e)
            {
                this.Logger.Error(e);
                throw;
            }
        }
Exemplo n.º 3
0
        public async new Task SaveBulkAsync(List <OtaSetting> settings)
        {
            this.Logger.Debug("Logging data");
            try
            {
                foreach (var s in settings)
                {
                    CriteriaBuilder criteriaBuilder = new CriteriaBuilder();
                    criteriaBuilder.Add("GroupName", s.GroupName).Add("Name", s.Name);
                    string            sql = this.QueryBuilder(criteriaBuilder);
                    List <OtaSetting> existingOtaSettings = await this.SelectQueryAsync(sql);

                    OtaSetting existing = (existingOtaSettings == null || existingOtaSettings.Count == 0) ? null : existingOtaSettings[0];

                    if (existing == null || existing.Id == default(Guid))
                    {
                        this.Logger.Debug(string.Format("Saving OtaSetting {0} for the first time.", s.Name));
                        await this.SaveAsync(s);
                    }
                    else
                    {
                        this.Logger.Debug(
                            string.Format("Updating existing OtaSetting {0} with {1}", existing.Value, s.Value));
                        existing.Value = s.Value;
                        await this.SaveAsync(existing);
                    }
                }
            }
            catch (Exception exception)
            {
                this.Logger.Debug(exception);
                throw;
            }
        }
Exemplo n.º 4
0
        public async Task <List <TModel> > GetViewedItems <TModel>(List <TModel> itemsToTest)
            where TModel : BusinessEntityBase
        {
            if (itemsToTest == null || itemsToTest.Count == 0)
            {
                return(new List <TModel>());
            }

            CriteriaBuilder criteriaBuilder = new CriteriaBuilder();

            List <SalesAppNotification> viewedNotifications = await GetManyByCriteria(
                criteriaBuilder
                .Add("Entity", itemsToTest[0].TableName)
                .Add("EntityId", itemsToTest.Select(item => item.Id).ToArray(), ConjunctionsEnum.And, Operators.In)
                .Add("NotificationStatus", NotificationStatus.Viewed)
                );

            if (viewedNotifications == null || viewedNotifications.Count == 0)
            {
                return(new List <TModel>());
            }

            List <string> intersectingId = viewedNotifications.Select(a => a.EntityId)
                                           .Intersect(itemsToTest.Select(item => item.Id.ToString())).ToList();

            return(itemsToTest.Where(item => intersectingId.Contains(item.Id.ToString())).ToList());
        }
Exemplo n.º 5
0
        private async Task <object> GetSynchronizableModelBase(string tableName, Guid requestId)
        {
            CriteriaBuilder criteriaBuilder = new CriteriaBuilder();
            Criterion       criterion       = new Criterion("RequestId", requestId);

            criteriaBuilder.Add(criterion);

            if (tableName.AreEqual(TableProspects))
            {
                return(await new ProspectsController(_lang, _country)
                       .GetSingleByCriteria(criteriaBuilder));
            }

            if (tableName.AreEqual(TableCustomer))
            {
                return(await new CustomersController()
                       .GetSingleByCriteria(criteriaBuilder));
            }

            string error =
                string.Format(
                    "Unable to retrieve record from table {0} for syncing as specific controller for the table has not been setup in SyncingController", tableName);

            throw new Exception(error);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns the current database's newVersion number
        /// </summary>
        public async Task <int> GetVersion()
        {
            try
            {
                if (DbConnection.Instance.Configured == false)
                {
                    return(0);
                }
                CriteriaBuilder cb = new CriteriaBuilder();
                cb.Add("Version", 0, ConjunctionsEnum.And, Operators.GreaterThan);
                DatabaseVersion dbVersion = await DataAccess.Instance.GetSingle <DatabaseVersion>
                                            (
                    cb
                                            );

                if (dbVersion == null)
                {
                    return(0);
                }
                else
                {
                    return(dbVersion.Version);
                }
            }
            catch (Exception erException)
            {
                if (erException.Message.ToLower().Contains("no such table"))
                {
                    return(0);
                }
                throw;
            }
        }
Exemplo n.º 7
0
        private async Task DeleteDuplicates(SQLiteConnection tran, StatHeader model)
        {
            CriteriaBuilder criteriaBuilder = new CriteriaBuilder();
            StatHeader      header          = await GetSingleByCriteria(
                criteriaBuilder
                .Add("Period", model.Period)
                .AddDateCriterion("From", model.From)
                .AddDateCriterion("To", model.To));

            if (header != null)
            {
                Logger.Debug("Deleting duplicate records");
                await new StatsController().DeleteWithCriteriaAsync(tran, new[]
                {
                    new Criterion("StatHeaderId", header.Id)
                }
                                                                    );

                await DeleteWithCriteriaAsync(tran, new[]
                {
                    new Criterion("Id", header.Id)
                });
            }
            else
            {
                Logger.Debug("No duplicate records to delete");
            }
        }
Exemplo n.º 8
0
        public override async Task SetOverdueNotificationsAsync(List <string> overdueNotifications)
        {
            CriteriaBuilder criteriaBuilder = new CriteriaBuilder();

            _overdueNotifications = overdueNotifications;
            _followUps            = await _followUpsController.GetManyByCriteria
                                    (
                criteriaBuilder
                .Add("Id", _overdueNotifications.ToArray(), ConjunctionsEnum.And, Operators.In)
                                    );

            List <Guid> followUpsToRemove = new List <Guid>();

            for (int i = 0; i < _followUps.Count; i++)
            {
                if ((await ProspectWasConverted(_followUps[i])))
                {
                    followUpsToRemove.Add(_followUps[i].Id);
                }
            }
            if (followUpsToRemove.Count > 0)
            {
                _followUps = Enumerable.ToList(Enumerable.Where(_followUps, followup => !followUpsToRemove.Contains(followup.Id)));
            }

            if (_followUps.Count == 1 && _singleProspect == null)
            {
                _singleProspect = await new ProspectsController().GetByIdAsync(_followUps[0].ProspectId);
                _singleProspect.ReminderTime = _followUps[0].ReminderTime;
            }
        }
Exemplo n.º 9
0
        public async Task <bool> IsProductActiveAsync(Guid customerId)
        {
            CriteriaBuilder criteriaBuilder = new CriteriaBuilder();
            List <CustomerRegistrationStepsStatus> allForCustomer = await this.GetManyByCriteria(
                criteriaBuilder
                .Add("CustomerId", customerId));

            if (allForCustomer == null || allForCustomer.Count == 0)
            {
                return(false);
            }

            Logger.Debug("Steps for customer ~".GetFormated(customerId));
            Logger.Debug("Steps count ~".GetFormated(allForCustomer.Count));

            foreach (var step in allForCustomer)
            {
                Logger.Debug("Step: ~ Value: ~".GetFormated(step.StepName, step.StepStatus));
            }

            if (allForCustomer.Count == 0)
            {
                Logger.Debug("Found no steps");
                return(false);
            }

            bool active = allForCustomer.All(step => step.StepStatus.AreEqual("done") != false);

            Logger.Debug("Customer ~ IsRejected = ~".GetFormated(customerId, active));
            return(active);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Gets an entity's down sync track record
        /// </summary>
        /// <param name="entity">The entity name to get</param>
        /// <returns>The tracking record matching the given entity</returns>
        public async Task <DownSyncTracker> Get(string entity)
        {
            CriteriaBuilder criteriaBuilder = new CriteriaBuilder();

            criteriaBuilder.Add("Entity", entity);
            return(await this.Controller.GetSingleByCriteria(criteriaBuilder));
        }
Exemplo n.º 11
0
        private CriteriaBuilder GetCriteriaBuilder(string entity, string entityId)
        {
            CriteriaBuilder criteriaBuilder = new CriteriaBuilder();

            return(criteriaBuilder
                   .Add("Entity", entity)
                   .Add("EntityId", entityId));
        }
Exemplo n.º 12
0
        public void WhenAddConditoinedCriteria_ShouldHaveExpressionInQuery()
        {
            var queryBuilder = new CriteriaBuilder <int>();

            queryBuilder.Add(() => true, num => num > 5);
            queryBuilder.Add(() => false, num => num < 5);

            var query = Enumerable.Range(1, 10)
                        .AsQueryable();

            query = queryBuilder.Build(query);

            var result = query.ToArray();

            Assert.AreEqual(5, result.Count());
            Assert.AreEqual(6, result.First());
        }
Exemplo n.º 13
0
        public async Task <List <TModel> > GetListByPeriodAndArea(Period period, SalesAreaHierarchy region)
        {
            CriteriaBuilder criteriaBuilder = new CriteriaBuilder();

            return(await LocalController.GetManyByCriteria(
                       criteriaBuilder
                       .Add("Period", (int)period)
                       .Add("Region", (int)region)));
        }
Exemplo n.º 14
0
        public async Task DeletePhotos(string nationalId)
        {
            CriteriaBuilder builder = new CriteriaBuilder();

            builder.Add("CustomerIdentifier", nationalId);
            builder.Add("PhotoUploadStatus", "1");
            List <CustomerPhoto> customerPhotos = await new CustomerPhotoController().GetManyByCriteria(builder);

            foreach (var photo in customerPhotos)
            {
                File file = new File(photo.FilePath);
                if (file.Exists())
                {
                    file.Delete();
                }

                new CustomerPhotoController().DeleteAsync(photo);
            }
        }
Exemplo n.º 15
0
        public async virtual Task <List <CustomerPhoto> > GetCustomerPhotos(string nationalId)
        {
            CriteriaBuilder criteria = new CriteriaBuilder();

            criteria.Add("CustomerIdentifier", nationalId);

            List <CustomerPhoto> photos = await this._controller.GetManyByCriteria(criteria);

            return(photos);
        }
Exemplo n.º 16
0
        private static void ProcessCriteria(XElement parent, CriteriaBuilder builder)
        {
            CriteriaBuilder newBuilder;

            foreach (var elem in parent.Elements().ToArray())
            {
                switch (elem.Name.LocalName)
                {
                case "Relationships":
                    break;

                case "not":
                    newBuilder = new CriteriaBuilder()
                    {
                        Not      = true,
                        Operator = "and",
                        Type     = builder.Type
                    };
                    ProcessCriteria(elem, newBuilder);
                    builder.Builders.Add(newBuilder);
                    elem.Remove();
                    break;

                case "and":
                    newBuilder = new CriteriaBuilder()
                    {
                        Not      = true,
                        Operator = "and",
                        Type     = builder.Type
                    };
                    ProcessCriteria(elem, newBuilder);
                    builder.Builders.Add(newBuilder);
                    elem.Remove();
                    break;

                case "or":
                    newBuilder = new CriteriaBuilder()
                    {
                        Not      = true,
                        Operator = "or",
                        Type     = builder.Type
                    };
                    ProcessCriteria(elem, newBuilder);
                    builder.Builders.Add(newBuilder);
                    elem.Remove();
                    break;

                default:
                    builder.Add(elem);
                    elem.Remove();
                    break;
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// This method retrieves the steps for a product of a customer and returns a object indicating:
        /// 1. Previous, Current and Next step
        /// 2. Current Step No
        /// 3. Total No of Step
        /// </summary>
        /// <param name="customerId">Customer to get the regsitration step for</param>
        /// <returns>Overview of steps for the customer product registration</returns>
        public async Task <RegistrationStatusOverview> GetVisibleSteps(Guid customerId)
        {
            CriteriaBuilder criteriaBuilder = new CriteriaBuilder();

            // Create the resulting object
            List <CustomerRegistrationStepsStatus> statusList = await _customerRegistration.GetManyByCriteria(
                criteriaBuilder
                .Add("CustomerId", customerId));

            return(await this.GetOverViewAsync(statusList));
        }
Exemplo n.º 18
0
        void InitializeData()
        {
            if (null != Intent)
            {
                Bundle extras = Intent.Extras;
                _originalProspect = extras != null?JsonConvert.DeserializeObject <ProspectItem>(extras.GetString(ExistingProspectId)) : null;

                _modifiedProspect = _originalProspect;
                bool exited = AsyncHelper.RunSync(async() => await ExitIfConverted());
                if (exited)
                {
                    return;
                }

                string origin = extras == null ? string.Empty : extras.GetString(ProspectDetailsOrigin);

                if (!string.IsNullOrEmpty(origin))
                {
                    Enum.TryParse(origin, out this._origin);
                }

                Task.Run
                (
                    async() =>
                {
                    {
                        if (_originalProspect.SearchResult.ReminderTime != default(DateTime))
                        {
                            CriteriaBuilder criteriaBuilder = new CriteriaBuilder();

                            ProspectFollowup followup = await new ProspectFollowUpsController()

                                                        .GetSingleByCriteria
                                                        (
                                criteriaBuilder
                                .Add("ProspectId", _originalProspect.SearchResult.Id)
                                .AddDateCriterion("ReminderTime", _originalProspect.SearchResult.ReminderTime)
                                                        );


                            if (followup != null && followup.Id != default(Guid))
                            {
                                await
                                new NotificationsCoreService().SetSingleNotificationViewed(
                                    followup.TableName,
                                    followup.Id.ToString());
                            }
                        }
                    }
                }
                );
            }
        }
Exemplo n.º 19
0
 private static void ProcessCriteria(XElement parent, CriteriaBuilder builder)
 {
   CriteriaBuilder newBuilder;
   foreach (var elem in parent.Elements())
   {
     switch (elem.Name.LocalName)
     {
       case "Relationships":
         break;
       case "not":
         newBuilder = new CriteriaBuilder()
         {
           Not = true,
           Operator = "and",
           Type = builder.Type
         };
         ProcessCriteria(elem, newBuilder);
         builder.Builders.Add(newBuilder);
         elem.Remove();
         break;
       case "and":
         newBuilder = new CriteriaBuilder()
         {
           Not = true,
           Operator = "and",
           Type = builder.Type
         };
         ProcessCriteria(elem, newBuilder);
         builder.Builders.Add(newBuilder);
         elem.Remove();
         break;
       case "or":
         newBuilder = new CriteriaBuilder()
         {
           Not = true,
           Operator = "or",
           Type = builder.Type
         };
         ProcessCriteria(elem, newBuilder);
         builder.Builders.Add(newBuilder);
         elem.Remove();
         break;
       default:
         builder.Add(elem);
         elem.Remove();
         break;
     }
   }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Reads and returns a setting from the database
        /// </summary>
        /// <param name="groupName">The group name</param>
        /// <param name="name">The setting name</param>
        /// <param name="defaultValue">The default value to return if nothing cannot be found</param>
        /// <returns>The given setting</returns>
        private async Task <OtaSetting> GetOtaSetting(string groupName, string name, OtaSetting defaultValue = null)
        {
            CriteriaBuilder criteriaBuilder = new CriteriaBuilder();

            try
            {
                this.Logger.Debug("Reading setting for " + name);
                OtaSetting setting =
                    await
                    this.SettingsController.GetSingleRecord(
                        criteriaBuilder.Add("GroupName", groupName).Add("Name", name));

                return(setting.Id == default(Guid) ? defaultValue : setting);
            }
            catch (Exception exception)
            {
                this.Logger.Error(exception);
                throw;
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Returns a single entity whose id is matches the one passed into the method
        /// </summary>
        /// <param name="id">The id to search for</param>
        /// <returns>A object that matches the id or null if none was found</returns>
        /// <exception cref="TimeoutException">Throws a TimeoutException if call doesn't complete within specified time duration</exception>
        public async Task <T> GetByIdAsync(Guid id)
        {
            try
            {
                T obj = null;
                await DataAccess.Instance.Connection.RunInTransactionAsync(
                    async connTran =>
                {
                    DataAccess.Instance.StartTransaction(connTran);
                    CriteriaBuilder criteria = new CriteriaBuilder();
                    criteria.Add("Id", id);
                    obj = await DataAccess.Instance.GetSingle <T>(criteria);
                });

                DataAccess.Instance.CommitTransaction();

                return(obj);
            }
            catch (Exception ex)
            {
                this.Logger.Debug(ex);
                return(null);
            }
        }
Exemplo n.º 22
0
        public async void UpdateUi(bool calledFromUiThread = false)
        {
            if (!calledFromUiThread)
            {
                Activity.RunOnUiThread(() => UpdateUi(true));
                return;
            }

            this.ShowSmsSendingStatus();
            _txtCustomerName.Text = _customerSearchResult.FullName;

            _txtCustomerPhone.Text   = _customerSearchResult.Phone;
            _txtCustomerProduct.Text = _customerSearchResult.Product.DisplayName;
            bool connectedToInternet            = Resolver.Instance.Get <IConnectivityService>().HasConnection();
            RegistrationStatusOverview overview = null;

            try
            {
                ShowSteps(false);
                _txtRegistrationProcessSteps.Text = GetString(Resource.String.loading_status);
                _loadingAnimation.Visibility      = ViewStates.Visible;

                if (connectedToInternet)
                {
                    var status = await _customerSearchResult.GetStatusAsync();

                    Customer c = new Customer
                    {
                        Id        = _customerSearchResult.Id,
                        Phone     = _customerSearchResult.Phone,
                        FirstName = _customerSearchResult.FullName,
                        LastName  = _customerSearchResult.LastName
                    };

                    if (status != null && status.Steps != null && status.AdditionalInfo != null)
                    {
                        overview = await _registrationStatusService.GetVisibleSteps(c, status.Steps, status.AdditionalInfo);

                        Intent callerIntent = new Intent(this.Activity, typeof(CustomerListView));
                        callerIntent.PutExtra(CustomerListView.CustomerStatusBundled, JsonConvert.SerializeObject(status));
                        this.Activity.SetResult(Result.Ok, callerIntent);
                    }
                }
                else
                {
                    await _registrationStatusService.GetVisibleSteps(_customerSearchResult.Id);
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception);
            }
            finally
            {
                // always hide the loader
                _loadingAnimation.Visibility = ViewStates.Gone;
            }

            if (FragmentWasUnloaded)
            {
                return;
            }

            if (!connectedToInternet)
            {
                CriteriaBuilder criteriaBuilder = new CriteriaBuilder();
                var             regStatus       = await new CustomerRegistrationStepsStatusController()
                                                  .GetManyByCriteria(
                    criteriaBuilder
                    .Add("CustomerId", _customerSearchResult.Id));

                if (regStatus != null)
                {
                    var status = regStatus.OrderByDescending(reg => reg.Modified).FirstOrDefault();
                    if (status != null && !status.AdditionalInfo.IsBlank())
                    {
                        _txtExtraInformation.Text       = status.AdditionalInfo;
                        _txtExtraInformation.Visibility = ViewStates.Visible;
                    }
                }
            }
            else
            {
                if (overview != null && overview.HasCurrentStep && !overview.CurrentStep.AdditionalInfo.IsBlank())
                {
                    _txtExtraInformation.Text       = overview.CurrentStep.AdditionalInfo;
                    _txtExtraInformation.Visibility = ViewStates.Visible;
                }
            }

            if (overview == null)
            {
                ShowSteps(false);
                _txtSmsSendInfo.Visibility = SmsInfoViewState;
            }
            else
            {
                ShowSteps(true);
                _txtRegistrationProcessSteps.Text = string.Format(
                    GetString(Resource.String.registration_process_steps),
                    overview.CurrentStepNo != 0 ? overview.CurrentStepNo : overview.TotalSteps,
                    overview.TotalSteps);

                if (overview.HasPreviousStep)
                {
                    _linStepDoneNo.Visibility = ViewStates.Visible;
                    _lineStepDone.Visibility  = ViewStates.Visible;
                    _txtStepDoneNo.Text       = overview.PreviousStep.StepNumber.ToString();
                    _txtStepDone.Text         = overview.PreviousStep.StepName;
                }
                else
                {
                    _linStepDoneNo.Visibility = ViewStates.Gone;
                    _lineStepDone.Visibility  = ViewStates.Gone;
                }

                if (overview.HasCurrentStep)
                {
                    _linStepCurrentNo.Visibility = ViewStates.Visible;
                    _lineStepCurrent.Visibility  = ViewStates.Visible;
                    _txtStepCurrentNo.Text       = overview.CurrentStep.StepNumber.ToString();
                    _txtStepCurrent.Text         = overview.CurrentStep.StepName;
                }
                else
                {
                    _linStepCurrentNo.Visibility = ViewStates.Gone;
                    _lineStepCurrent.Visibility  = ViewStates.Gone;
                }

                if (overview.HasFutureStep)
                {
                    _linStepFutureNo.Visibility = ViewStates.Visible;
                    _txtStepFutureNo.Text       = overview.FutureStep.StepNumber.ToString();
                    _txtStepFuture.Text         = overview.FutureStep.StepName;
                }
                else
                {
                    _lineStepCurrent.Visibility = ViewStates.Gone;
                    _linStepFutureNo.Visibility = ViewStates.Gone;
                }
            }

            ActivityBase activity = Activity as ActivityBase;

            if (activity != null)
            {
                activity.SetScreenTitle(_customerSearchResult.FullName);
            }
        }
Exemplo n.º 23
0
 public BuildTypeLocator With(string dimension, string value)
 {
     _criteriaBuilder.Add(dimension, value);
     return(this);
 }
Exemplo n.º 24
0
        public async Task <List <ProspectFollowup> > GetOverdueRemindersAsync()
        {
            CriteriaBuilder         criteriaBuilder = new CriteriaBuilder();
            List <ProspectFollowup> followups       = await GetManyByCriteria(
                criteriaBuilder
                .AddDateCriterion("ReminderTime", DateTime.Now, ConjunctionsEnum.And,
                                  Operators.LessThanOrEqualTo, true, true));

            if (followups == null || followups.Count == 0)
            {
                Logger.Debug("There are no followup reminders");
                return(new List <ProspectFollowup>());
            }

            Logger.Debug("Number of over due reminders is ~".GetFormated(followups.Count));
            string[] prospectIds = followups.Where(followup => followup.ProspectId != default(Guid))
                                   .Select(a => a.ProspectId.ToString())
                                   .ToArray();

            Logger.Debug("No null prospect ids count is ~".GetFormated(prospectIds.Length));

            criteriaBuilder = new CriteriaBuilder();

            List <Prospect> prospects = await new ProspectsController().GetManyByCriteria(criteriaBuilder
                                                                                          .Add("Id", prospectIds, ConjunctionsEnum.And, Operators.In));

            if (prospects == null || prospects.Count == 0)
            {
                return(new List <ProspectFollowup>());
            }

            return
                (followups.Where(followup => prospects.Select(prosp => prosp.Id).Contains(followup.ProspectId)).ToList());
        }
Exemplo n.º 25
0
        /// <summary>
        /// Saves customer status and if necessary the related product.
        /// If the status details for the product already exist, they are deleted
        /// </summary>
        /// <param name="status">The status as supplied by the server</param>
        /// <param name="customer">The customer</param>
        /// <param name="connTran">The connection object for wrapping db calls in a transaction</param>
        /// <returns>A list of all saved items or null if the status was null</returns>
        /// <exception cref="NotSavedException">NotSavedException is thrown if even one item could not be saved</exception>
        public async Task <List <CustomerRegistrationStepsStatus> > SaveAsync(SQLiteConnection connTran, CustomerStatus status, Customer customer)
        {
            if (status == null || status.CustomerNotFound.IsBlank() == false)
            {
                return(null);
            }

            if (status.CustomerProduct.IsBlank())
            {
                status.CustomerProduct = "Product III";
            }

            CriteriaBuilder criteriaBuilder = new CriteriaBuilder();

            criteriaBuilder.Add("DisplayName", status.CustomerProduct);

            string         query    = this.ProductsController.QueryBuilder(criteriaBuilder);
            List <Product> products = await this.ProductsController.SelectQueryAsync(query);

            Product product = null;

            if (products != null)
            {
                product = products.OrderByDescending(prod => prod.Modified).FirstOrDefault();
            }

            List <CustomerRegistrationStepsStatus> resultList = new List <CustomerRegistrationStepsStatus>();

            if (product == null)
            {
                product = new Product
                {
                    DisplayName = status.CustomerProduct
                };

                await this.ProductsController.SaveAsync(connTran, product);
            }
            else
            {
                string sql =
                    string.Format(
                        "Delete from CustomerRegistrationStepsStatus where ProductId='{0}' and CustomerId='{1}'",
                        product.Id, customer.Id);
                await DataAccess.Instance.RunQueryAsync(sql);
            }

            if (status.Steps != null)
            {
                foreach (var step in status.Steps)
                {
                    CustomerRegistrationStepsStatus registrationStepsStatus = new CustomerRegistrationStepsStatus
                    {
                        CustomerId     = customer.Id,
                        ProductId      = product.Id,
                        RequestStatus  = status.RequestStatus,
                        StepName       = step.StepName,
                        StepNumber     = step.StepNumber,
                        StepStatus     = step.StepStatus,
                        AdditionalInfo = status.AdditionalInfo
                    };

                    var saveResponse = await base.SaveAsync(connTran, registrationStepsStatus);

                    if (saveResponse.SavedModel != null)
                    {
                        resultList.Add(saveResponse.SavedModel);
                    }
                    else
                    {
                        throw new NotSavedException();
                    }
                }
            }

            SyncingController syncingController = new SyncingController();
            SyncRecord        syncRecord        = await syncingController.GetSyncRecordAsync(customer.RequestId);

            if (syncRecord != null)
            {
                syncRecord.Status = RecordStatus.Synced;
                await syncingController.SaveAsync(connTran, syncRecord);
            }

            return(resultList);
        }