public ActionResult StateCreatePopup(string btnId, string formId, StateProvinceModel model)
        {
            var country = _countryService.GetCountryById(model.CountryId);

            if (country == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var sp = model.ToEntity();

                _stateProvinceService.InsertStateProvince(sp);
                UpdateLocales(sp, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId       = btnId;
                ViewBag.formId      = formId;

                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#2
0
        public virtual IActionResult StateCreatePopup(StateProvinceModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedView());
            }

            var country = _countryService.GetCountryById(model.CountryId);

            if (country == null)
            {
                //No country found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var sp = model.ToEntity();

                _stateProvinceService.InsertStateProvince(sp);

                //activity log
                _customerActivityService.InsertActivity("AddNewStateProvince",
                                                        string.Format(_localizationService.GetResource("ActivityLog.AddNewStateProvince"), sp.Id), sp);

                UpdateLocales(sp, model);

                ViewBag.RefreshPage = true;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#3
0
        public ActionResult StateCreatePopup(string btnId, string formId, StateProvinceModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedView());
            }

            var country = _countryService.GetCountryById(model.CountryId);

            if (country == null)
            {
                //No country found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var sp = model.ToEntity();

                _stateProvinceService.InsertStateProvince(sp);
                UpdateLocales(sp, model);

                ViewBag.RefreshPage = true;
                ViewBag.btnId       = btnId;
                ViewBag.formId      = formId;
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#4
0
        public virtual async Task <StateProvince> InsertStateProvinceModel(StateProvinceModel model)
        {
            var sp = model.ToEntity();
            await _stateProvinceService.InsertStateProvince(sp);

            return(sp);
        }
示例#5
0
        public virtual StateProvince InsertStateProvinceModel(StateProvinceModel model)
        {
            var sp = model.ToEntity();

            _stateProvinceService.InsertStateProvince(sp);
            return(sp);
        }
示例#6
0
        public ActionResult Create(StateProvinceViewModel model)
        {
            try
            {
                if (model.CountryId == 0)
                {
                    ModelState.AddModelError("", "select country");
                }

                if (ModelState.IsValid)
                {
                    var stateProvince = new StateProvince
                    {
                        Name         = model.Name,
                        Published    = model.Published,
                        DisplayOrder = model.DisplayOrder,
                        Abbreviation = model.Abbreviation,
                        CountryId    = model.CountryId
                    };
                    _stateProvinceService.InsertStateProvince(stateProvince);
                    SuccessNotification("State added successfully.");
                    return(RedirectToAction("List"));
                }
                model.AvailableCountry = GetCountryList();
                ErrorNotification("Fill required fields");
                return(View(model));
            }
            catch (System.Exception)
            {
                throw;
            }
        }
示例#7
0
        public ActionResult Create(StateProvinceViewModel model)
        {
            if (model.CountryId == 0)
            {
                ModelState.AddModelError("", "select country");
            }

            if (ModelState.IsValid)
            {
                var stateProvince = new StateProvince
                {
                    Name         = model.Name,
                    Published    = model.Published,
                    DisplayOrder = model.DisplayOrder,
                    Abbreviation = model.Abbreviation,
                    CountryId    = model.CountryId
                };
                _stateProvinceService.InsertStateProvince(stateProvince);
                return(RedirectToAction("List"));
            }
            model.AvailableCountry = GetCountryList();
            return(View(model));
        }
示例#8
0
 /// <summary>
 /// Inserts a state/province
 /// </summary>
 /// <param name="stateProvince">State/province</param>
 void InsertStateProvince(StateProvince stateProvince)
 {
     _stateProvinceService.InsertStateProvince(stateProvince);
 }
示例#9
0
        /// <summary>
        /// Import states from TXT file
        /// </summary>
        /// <param name="stream">Stream</param>
        /// <returns>Number of imported states</returns>
        public virtual int ImportStatesFromTxt(Stream stream)
        {
            int count = 0;

            using (var reader = new StreamReader(stream))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();
                    if (String.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }
                    string[] tmp = line.Split(',');

                    if (tmp.Length != 5)
                    {
                        throw new NopException("Wrong file format");
                    }

                    //parse
                    var  countryTwoLetterIsoCode = tmp[0].Trim();
                    var  name         = tmp[1].Trim();
                    var  abbreviation = tmp[2].Trim();
                    bool published    = Boolean.Parse(tmp[3].Trim());
                    int  displayOrder = Int32.Parse(tmp[4].Trim());

                    var country = _countryService.GetCountryByTwoLetterIsoCode(countryTwoLetterIsoCode);
                    if (country == null)
                    {
                        //country cannot be loaded. skip
                        continue;
                    }

                    //import
                    var states = _stateProvinceService.GetStateProvincesByCountryId(country.Id, true);
                    var state  = states.FirstOrDefault(x => x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));

                    if (state != null)
                    {
                        state.Abbreviation = abbreviation;
                        state.Published    = published;
                        state.DisplayOrder = displayOrder;
                        _stateProvinceService.UpdateStateProvince(state);
                    }
                    else
                    {
                        state = new StateProvince
                        {
                            CountryId    = country.Id,
                            Name         = name,
                            Abbreviation = abbreviation,
                            Published    = published,
                            DisplayOrder = displayOrder,
                        };
                        _stateProvinceService.InsertStateProvince(state);
                    }
                    count++;
                }
            }

            return(count);
        }
示例#10
0
        public void ImportProvincesFromXlsx(Stream stream, int countryId)
        {
            using (var xlPackage = new ExcelPackage(stream))
            {
                // get the first worksheet in the workbook
                var worksheet = xlPackage.Workbook.Worksheets.FirstOrDefault();
                if (worksheet == null)
                {
                    throw new NopException("No worksheet found");
                }

                //the columns
                var properties = GetPropertiesByExcelCells <StateProvince>(worksheet);

                var manager = new PropertyManager <StateProvince>(properties);

                var iRow      = 2;
                var setSeName = properties.Any(p => p.PropertyName == "SeName");

                while (true)
                {
                    var allColumnsAreEmpty = manager.GetProperties
                                             .Select(property => worksheet.Cells[iRow, property.PropertyOrderPosition])
                                             .All(cell => cell == null || cell.Value == null || String.IsNullOrEmpty(cell.Value.ToString()));

                    if (allColumnsAreEmpty)
                    {
                        break;
                    }

                    manager.ReadFromXlsx(worksheet, iRow);



                    //var seName = string.Empty;
                    string name         = "";
                    string postalCode   = "";
                    string abbreviation = "";
                    foreach (var property in manager.GetProperties)
                    {
                        switch (property.PropertyName)
                        {
                        case "Name":
                            name = property.StringValue;
                            break;

                        case "PostalCode":
                            postalCode = property.StringValue;
                            break;

                        case "Abbreviation":
                            abbreviation = property.StringValue;
                            break;
                        }
                    }

                    var stateProvince = _stateProvinceService.GetStateProvinceByAbbreviation(abbreviation) ?? new StateProvince
                    {
                        Published    = true,
                        CountryId    = countryId,
                        Name         = name,
                        Abbreviation = abbreviation,
                        Id           = 0
                    };

                    var isNew = stateProvince.Id == 0;
                    if (isNew)
                    {
                        _stateProvinceService.InsertStateProvince(stateProvince);
                    }
                    else
                    {
                        _stateProvinceService.UpdateStateProvince(stateProvince);
                    }
                    if (stateProvince.Id > 0)
                    {
                        var postalCodes = postalCode.Split(',').ToList();
                        if (postalCodes != null)
                        {
                            foreach (var postal in postalCodes)
                            {
                                var stateProvinceWB = _stateProvinceWBService.GetByPostalCodeAndProvinceID(postal, stateProvince.Id) ?? new StateProvincePostalCode
                                {
                                    Id = 0,
                                    StateProvinceID = stateProvince.Id,
                                    PostalCode      = postal
                                };
                                if (stateProvinceWB.Id == 0)
                                {
                                    _stateProvinceWBService.Insert(stateProvinceWB);
                                }
                            }
                        }
                    }
                    iRow++;
                }
            }
        }