public ActionResult Upsert(int?id)
        {
            StoreUpModel model = null;

            try
            {
                using (var repository = new StoreRepository())
                {
                    if (id.HasValue)
                    {
                        model = repository.FindModelById(id.Value);
                    }
                    else
                    {
                        model = new StoreUpModel
                        {
                            FranchiseStoreId = EntityConstants.NULL_VALUE
                        };
                    }
                    ViewBag.LstFranchises     = JsonConvert.SerializeObject(repository.GetFranchises());
                    ViewBag.LastRegion        = FactoryAddress.GetRegionChildByZipCode();
                    ViewBag.RegionsEnabled    = JsonConvert.SerializeObject(FactoryAddress.GetAddressHierarchyOrderById());
                    ViewBag.RegionLang        = JsonConvert.SerializeObject(SettingsData.Constants.AddressUpsertSetting);
                    ViewBag.ManagerStoreUsers = JsonConvert.SerializeObject(new AccountRepository(repository.Db).GetManagerStoreUsers());
                    ViewBag.Address           = JsonConvert.SerializeObject(model.Address);
                    model.Address             = null;
                    ViewBag.Model             = JsonConvert.SerializeObject(model);
                }
            }
            catch (Exception ex)
            {
                SharedLogger.LogError(ex, id);
            }
            return(View(model));
        }
        public ResponseMessageData <AddressInfoModel> SaveAddress(AddressInfoModel model)
        {
            using (_repository)
            {
                if (model.IsMap)
                {
                    model.AddressId = _repository.SaveAddressMap(model, model.AddressId == null || model.AddressId == SharedConstants.NULL_ID_VALUE);
                }
                else
                {
                    if (model.ZipCode == null || model.ZipCode.IdKey == null || model.ZipCode.IdKey <= 0)
                    {
                        var lastRegion = SettingsData.LastRegion;
                        model.ZipCode = FactoryAddress.GetQueryToGetByZipCodeId(_repository.InnerDbEntities, lastRegion, model);
                    }

                    model.AddressId = _repository.SaveAddress(model, model.AddressId == null || model.AddressId == SharedConstants.NULL_ID_VALUE);
                }

                return(new ResponseMessageData <AddressInfoModel>
                {
                    Data = model,
                    IsSuccess = true,
                    Message = String.Empty
                });
            }
        }
 public IEnumerable <AddressResponseSearch> SearchHierarchyByZipCode(string zipCode)
 {
     using (_repository)
     {
         var query = FactoryAddress.GetQueryToExecByZipCode(_repository.InnerDbEntities, zipCode);
         return(query.ToList());
     }
 }
        public StoreModel StoreAvailableForAddress(StoreAvailableModel model, ResponseMessageData <StoreModel> response)
        {
            using (_repositoryStore)
            {
                int franchiseId;
                var stores = FactoryAddress.GetQueryToSearchStore(_repositoryStore.InnerDbEntities, model.FranchiseCode,
                                                                  model.AddressInfo, out franchiseId);

                return(GetStoreAvailable(response, stores, true));
            }
        }
        public IEnumerable <ListItemModel> FillNextListByName(string sNextList, int iIdSelected, out string sControlName)
        {
            if (String.IsNullOrWhiteSpace(sNextList))
            {
                sNextList = SettingsData.FirstRegion;
                //foreach (var control in SettingsData.Constants.AddressUpsertSetting.LstAddressControls.Where(control => control.IsEnabled))
                //{
                //    sNextList = control.Name;
                //    break;
                //}
            }
            sControlName = sNextList;

            using (_repository)
            {
                var query = FactoryAddress.GetQueryToFillNextListByName(_repository.InnerDbEntities, sNextList, iIdSelected);
                return(query.ToList());
            }
        }
Beispiel #6
0
 public ActionResult ZipCodes(string code)
 {
     try
     {
         using (var repository = new CallCenterEntities())
         {
             var data = FactoryAddress.GetQueryToExecByZipCode(repository, code, true).ToList();
             return(Json(new ResponseMessageModel
             {
                 HasError = false,
                 Data = data,
             }));
         }
     }
     catch (Exception ex)
     {
         SharedLogger.LogError(ex);
         return(Json(new ResponseMessageModel
         {
             HasError = false,
             Message = "Se presentó un problema al momento de consultar la información",
         }));
     }
 }
Beispiel #7
0
        public ResponseMessageModel ValidateModel(StoreUpModel model)
        {
            var response = new ResponseMessageModel {
                HasError = true
            };

            if (_repositoryStore.IsFranchiseValidById(model.FranchiseId) == false)
            {
                response.Message = "La franquicia no es válida";
                return(response);
            }

            if (_repositoryStore.IsValidManagerStoreUserId(model.ManUserId) == false)
            {
                response.Message = "El usuario no tiene el perfil necesario, no es válido o no existe";
                return(response);
            }

            var address = model.Address;

            if (address == null)
            {
                response.Message = "No se ha definido la dirección";
                return(response);
            }


            var          regionChild = FactoryAddress.GetRegionChildByZipCode();
            AddressModel addressRes  = null;

            switch (regionChild)
            {
            case AddressConstants.REGION_A:
            {
                addressRes = _repositoryStore.IsValidRegionA(address.RegionArId);
                break;
            }

            case AddressConstants.REGION_B:
            {
                addressRes = _repositoryStore.IsValidRegionB(address.RegionBrId);
                break;
            }

            case AddressConstants.REGION_C:
            {
                addressRes = _repositoryStore.IsValidRegionC(address.RegionCrId);
                break;
            }

            case AddressConstants.REGION_D:
            {
                addressRes = _repositoryStore.IsValidRegionD(address.RegionDrId);
                break;
            }
            }

            if (addressRes == null)
            {
                response.Message = "La dirección no es correcta debido a la configuración";
                return(response);
            }

            addressRes.MainAddress = address.MainAddress;
            addressRes.NumExt      = address.NumExt;
            addressRes.Reference   = address.Reference;

            model.AddressRes  = addressRes;
            response.HasError = false;
            return(response);
        }