示例#1
0
        public ActionResult MergeInto(int id)
        {
            Location loc = this.locationTasks.GetLocation(id);

            if (loc != null)
            {
                LocationMergeViewModel vm = new LocationMergeViewModel();
                Mapper.Map <Location, LocationMergeViewModel>(loc, vm);
                if (loc.Region != null)
                {
                    vm.RegionId = loc.Region.Id;
                }
                vm.NumEvents        = loc.Events.Count;
                vm.NumCareers       = loc.Careers.Count;
                vm.NumUnitLocations = loc.UnitLocations.Count;
                vm.PopulateDropDowns(this.locationTasks.GetAllRegions(), this.locationTasks.GetAllProvinces());
                return(View(vm));
            }
            return(new HttpNotFoundResult());
        }
示例#2
0
        public ActionResult MergeInto(LocationMergeViewModel vm)
        {
            if (ModelState.IsValid)
            {
                if (vm.Id != vm.ToDeleteLocationId)
                {
                    Location toKeep = this.locationTasks.GetLocation(vm.Id);
                    Mapper.Map <LocationMergeViewModel, Location>(vm, toKeep);
                    if (vm.RegionId.HasValue)
                    {
                        toKeep.Region = this.locationTasks.GetRegion(vm.RegionId.Value);
                    }
                    if (vm.ProvinceId.HasValue)
                    {
                        toKeep.Province = this.locationTasks.GetProvince(vm.ProvinceId.Value);
                    }

                    Location toDelete = this.locationTasks.GetLocation(vm.ToDeleteLocationId);

                    // currently talks straight to database; Lucene indexes not updated, normal audit trail skipped
                    this.locationTasks.MergeLocations(toKeep.Id, toDelete.Id);

                    this.locationTasks.DeleteLocation(toDelete);

                    return(RedirectToAction("Details", new { id = toKeep.Id }));
                }
                else
                {
                    ModelState.AddModelError("ToDeleteLocationId", "Can't merge same location.");
                    return(MergeInto(vm.Id));
                }
            }
            else
            {
                return(MergeInto(vm.Id));
            }
        }