Example #1
0
File: Item.cs Project: ucdavis/CRP
 public virtual void AddMapPin(MapPin mapPin)
 {
     mapPin.Item = this;
     MapPins.Add(mapPin);
 }
Example #2
0
File: Item.cs Project: ucdavis/CRP
 public virtual void RemoveMapPin(MapPin mapPin)
 {
     MapPins.Remove(mapPin);
 }
Example #3
0
        public ActionResult Edit(int itemId, int mapPinId, MapPin mapPin)
        {
            ModelState.Clear();
            var item = Repository.OfType<Item>().GetNullableById(itemId);
            if (item == null || !_accessControlService.HasItemAccess(CurrentUser, item))
            {
                //Don't Have editor rights
                Message = NotificationMessages.STR_NoEditorRights;
                return this.RedirectToAction<ItemManagementController>(a => a.List(null));
            }
            var mapPinToUpdate = Repository.OfType<MapPin>().GetNullableById(mapPinId);
            if (mapPinToUpdate == null || !item.MapPins.Contains(mapPinToUpdate))
            {
                Message = NotificationMessages.STR_ObjectNotFound.Replace(NotificationMessages.ObjectType, "MapPin");
                //return Redirect(Url.EditItemUrl(itemId, StaticValues.Tab_MapPins));
                return this.RedirectToAction<ItemManagementController>(a => a.Map(item.Id));
            }

            mapPinToUpdate.Latitude = mapPin.Latitude;
            mapPinToUpdate.Longitude = mapPin.Longitude;
            mapPinToUpdate.Title = mapPin.Title;
            mapPinToUpdate.Description = mapPin.Description;
            //mapPinToUpdate.Item = item;

            mapPinToUpdate.TransferValidationMessagesTo(ModelState);
            item.TransferValidationMessagesTo(ModelState);

            if(ModelState.IsValid)
            {
                //could replace with EnsurePersistent(item), but this is working fine.
                Repository.OfType<MapPin>().EnsurePersistent(mapPinToUpdate);
                Message = NotificationMessages.STR_ObjectSaved.Replace(NotificationMessages.ObjectType,
                                                                       "Map Pin");
                //return Redirect(Url.EditItemUrl(itemId, StaticValues.Tab_MapPins));
                return this.RedirectToAction<ItemManagementController>(a => a.Map(item.Id));
            }

            Message = "Unable to save Map Pin changes.";
            var viewModel = MapPinViewModel.Create(Repository, item);
            viewModel.MapPin = mapPinToUpdate;
            return View(viewModel);
        }