public void SaveStore(EditViewModel editViewModel)
        {
            var store = Map(editViewModel);

            if (editViewModel.StoreId == 0)
            {
                AddStore(store);
            }
            else
            {
                EditStore(store);
            }
        }
 private static Store Map(EditViewModel editViewModel)
 {
     return new Store
                {
                    StoreId = editViewModel.StoreId,
                    //Company = _companiesManagement.GetCompany( editFormModel.Company.CompanyId),
                    CompanyId = editViewModel.Company.CompanyId,
                    DistrictId = editViewModel.DistrictId,
                    FaxNumber = editViewModel.FaxNumber,
                    PhoneNumber1 = editViewModel.PhoneNumber1,
                    PhoneNumber2 = editViewModel.PhoneNumber2,
                    StoreName = editViewModel.StoreName.ToUpper(),
                };
 }
        //
        // GET: /Users/Create/
        public ActionResult Create()
        {
            var companies = _companiesManagement.GetCompaniesList();
            var editViewModel = new EditViewModel
            {
                StoreId = 0,
                StoreName = "",
                CompaniesList = companies,
                Company = new Company { CompanyId = 0 },
                FaxNumber = "",
                PhoneNumber1 = "",
                PhoneNumber2 = "",
                ProvinceId = _locationsManagement.GetProvince(1).ProvinceId,
                ProvincesList = _locationsManagement.GetAllProvinces(),
                CantonId = 1,
                CantonsList = _locationsManagement.GetCantonsByProvince(1),
                //CantonsList =
                DistrictId = 1,
                DistrictsList = _locationsManagement.GetDistrictsByCanton(1),
                //DistrictsList =
            };

            return View("Edit", editViewModel);
        }
        //
        // GET: /Stores/Edit/{id}
        public ActionResult Edit(int id)
        {
            var store = _storesManagement.GetStore(id);
            var companies = _companiesManagement.GetCompaniesList();
            var canton = _locationsManagement.GetCantonByDistrict(store.District.DistrictId);
            var province = _locationsManagement.GetProvinceByCanton(canton.CantonId);
            var editViewModel = new EditViewModel
            {
                StoreId = store.StoreId,
                StoreName = store.StoreName,
                Company = store.Company,
                CompaniesList = companies,

                FaxNumber = store.FaxNumber,
                PhoneNumber1 = store.PhoneNumber1,
                PhoneNumber2 = store.PhoneNumber2,

                ProvinceId = province.ProvinceId,
                ProvincesList = _locationsManagement.GetAllProvinces(),
                CantonId = canton.CantonId,
                CantonsList = _locationsManagement.GetCantonsByProvince(province.ProvinceId),
                DistrictId = store.DistrictId,
                DistrictsList = _locationsManagement.GetDistrictsByCanton(canton.CantonId),
            };
            return View(editViewModel);
        }
 public ActionResult Save(EditViewModel editViewModel)
 {
     if (ModelState.IsValid)
     {
         _storesManagement.SaveStore(editViewModel);
         return RedirectToAction("Index");
     }
     var canton = _locationsManagement.GetCantonByDistrict(editViewModel.DistrictId);
     var province = _locationsManagement.GetProvinceByCanton(canton.CantonId);
     editViewModel.ProvincesList = _locationsManagement.GetAllProvinces();
     editViewModel.CantonsList = _locationsManagement.GetCantonsByProvince(province.ProvinceId);
     editViewModel.DistrictsList = _locationsManagement.GetDistrictsByCanton(canton.CantonId);
     editViewModel.CompaniesList = _companiesManagement.GetCompaniesList();
     return View("Edit", editViewModel);
 }