public override ActionResult Index(int?id) { var entityViewModels = new List <BulletViewModel>(); IEnumerable <BulletView> entityViews; using (var localService = this.service as IBulletService) { if (id != null) { entityViews = from entityView in localService.GetBulletViews().ToList() where entityView.CaliberViewId == id select entityView; ViewBag.CaliberName = entityViews.First().CaliberViewName; } else { entityViews = localService.GetBulletViews().ToList(); ViewBag.CaliberName = "All Calibers"; } foreach (BulletView entityView in entityViews.OrderBy(ev => ev.CaliberViewSortOrder).ThenBy(ev => ev.Mass).ThenBy(ev => ev.Name)) { var entityViewModel = new BulletViewModel(); var entity = new Bullet { Id = entityView.Id, Name = entityView.Name, BulletTypeId = entityView.BulletTypeId, MaterialId = entityView.MaterialId, Diameter = entityView.Diameter, DiameterUnitId = entityView.DiameterUnitId, Mass = entityView.Mass, MassUnitId = entityView.MassUnitId, SectionalDensity = entityView.SectionalDensity, BallisticCoefficient = entityView.BallisticCoefficient, Length = entityView.Length, LengthUnitId = entityView.LengthUnitId, ManufacturerId = entityView.ManufacturerId, Notes = entityView.Notes }; entityViewModel.Entity = entity; entityViewModel.EntityView = entityView; entityViewModels.Add(entityViewModel); } } return(View(entityViewModels)); }
private void OnBulletCollision(object sender, EventArgs e) { if (sender is BulletViewModel) { BulletViewModel bulletViewModel = (BulletViewModel)sender; Destroy(bulletViewModel.gameObject); } }
public override void CreateViewModel() { if (UseEmptyViewModel || string.IsNullOrEmpty(ViewModelInitValueJson)) { VM = new BulletViewModel(); } else { VM = JsonConvert.DeserializeObject <BulletViewModel> (ViewModelInitValueJson); ViewModelPropertyRef(); } VM.AddHostView(ViewModelBase.DefaultViewBaseKey, this); }
public override void Initialize(ViewModelBase viewModel) { if (viewModel != null) { VM = (BulletViewModel)viewModel; VM.AddHostView(ViewModelBase.DefaultViewBaseKey, this); } else { if (AutoCreateViewModel && VM == null) { CreateViewModel(); } } base.Initialize(VM); }
public override ActionResult Delete(int?id) { var entityViewModel = new BulletViewModel(); using (var localService = this.service as IBulletService) { var entity = localService.FindById(id) as Bullet; var entityView = new BulletView { Id = entity.Id, Name = entity.Name, BulletTypeAbbreviation = entity.BulletType.Abbreviation, MaterialId = entity.MaterialId, MaterialName = entity.Material.Name, Diameter = entity.Diameter, DiameterUnitId = entity.DiameterUnitId, Mass = entity.Mass, MassUnitId = entity.MassUnitId, SectionalDensity = entity.SectionalDensity, BallisticCoefficient = entity.BallisticCoefficient, Length = entity.Length, LengthUnitId = entity.LengthUnitId, ManufacturerId = entity.ManufacturerId, ManufacturerName = entity.Manufacturer.Name, Notes = entity.Notes }; entityViewModel.CanDelete = !(entity.CartridgeLoads.Any() || entity.BulletQuantities.Any() || entity.BulletCosts.Any()); entityViewModel.Entity = entity; entityViewModel.EntityView = entityView; } return(View(entityViewModel)); }
public override ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var entityView = new BulletViewModel(); using (var localService = this.service as IBulletService) { var entity = localService.GetBulletViews().Where(b => b.Id == id).First() as BulletView; var newEntity = new Bullet { Id = entity.Id, Name = entity.Name, BulletTypeId = entity.BulletTypeId, MaterialId = entity.MaterialId, Diameter = entity.Diameter, DiameterUnitId = entity.DiameterUnitId, Mass = entity.Mass, MassUnitId = entity.MassUnitId, SectionalDensity = entity.SectionalDensity, BallisticCoefficient = entity.BallisticCoefficient, Length = entity.Length, LengthUnitId = entity.LengthUnitId, ManufacturerId = entity.ManufacturerId, Notes = entity.Notes }; entityView.Entity = newEntity; entityView.EntityView = entity; } return(View(entityView)); }
public override void SetViewModel(ViewModelBase viewModel) { VM = (BulletViewModel)viewModel; }