示例#1
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                string    name               = collection.Get("Name");
                Territory Territory          = new Territory();
                IRepository <Territory> repo = new TerritoryRepository();
                Territory = repo.GetById(id);
                Territory.ClearRegions();
                Territory.Name = name;
                string   param_regions;
                string[] arrayRegions;
                if (collection.Get("Regions") != null)
                {
                    param_regions = collection.Get("Regions");;
                    arrayRegions  = param_regions.Split(',');

                    foreach (string str in arrayRegions)
                    {
                        int    RegionID = Convert.ToInt32(str);
                        Region region   = new Region();
                        IRepository <Region> repo_region = new RegionRepository();
                        region = repo_region.GetById(RegionID);

                        Territory.Regions.Add(region);
                    }
                }

                repo.Update(Territory);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }