Example #1
0
        public override ActionResult Delete(int?id)
        {
            var entityViewModel = new CaliberViewModel();

            using (var localService = this.service as ICaliberService)
            {
                var entity     = localService.GetAll().OfType <Caliber>().Where(b => b.Id == id).First();
                var entityView = new CaliberView {
                    PrimerTypeAbbreviation = entity.PrimerType.Abbreviation, DiameterUnitViewAbbreviation = entity.DiameterUnit.Abbreviation, BrassLengthUnitViewAbbreviation = entity.BrassLengthUnit.Abbreviation
                };

                entityViewModel.CanDelete  = !(entity.Brasses.Any() || entity.CartridgeLoads.Any() || entity.Guns.Any());
                entityViewModel.Entity     = entity;
                entityViewModel.EntityView = entityView;
            }

            return(View(entityViewModel));
        }
Example #2
0
        public override ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var entityViewModel = new CaliberViewModel();

            using (var localService = this.service as ICaliberService)
            {
                var entity     = localService.GetAll().OfType <Caliber>().Where(c => c.Id == id).First();
                var entityView = new CaliberView {
                    PrimerTypeAbbreviation = entity.PrimerType.Abbreviation, DiameterUnitViewAbbreviation = entity.DiameterUnit.Abbreviation, BrassLengthUnitViewAbbreviation = entity.BrassLengthUnit.Abbreviation
                };

                entityViewModel.Entity     = entity;
                entityViewModel.EntityView = entityView;
            }

            return(View(entityViewModel));
        }
Example #3
0
        public override ActionResult Index(int?id)
        {
            ViewBag.Environment = ConfigurationManager.AppSettings.Get("Environment");

            var entityViewModels = new List <CaliberViewModel>();
            IEnumerable <Caliber> entityViews;

            using (var localService = this.service as ICaliberService)
            {
                if (id != null)
                {
                    entityViews = from entityView in localService.GetAll().OfType <Caliber>()
                                  where entityView.Id == id
                                  select entityView;
                    ViewBag.CaliberName = entityViews.First().Name;
                }
                else
                {
                    var x = localService.GetAll();
                    entityViews         = localService.GetAll().OfType <Caliber>().ToList();
                    ViewBag.CaliberName = "All Calibers";
                }

                foreach (Caliber entity in entityViews.OrderBy(ev => ev.SortOrder))
                {
                    var entityViewModel = new CaliberViewModel();
                    var entityView      = new CaliberView {
                        PrimerTypeAbbreviation = entity.PrimerType.Abbreviation, DiameterUnitViewAbbreviation = entity.DiameterUnit.Abbreviation, BrassLengthUnitViewAbbreviation = entity.BrassLengthUnit.Abbreviation
                    };

                    entityViewModel.Entity     = entity;
                    entityViewModel.EntityView = entityView;
                    entityViewModels.Add(entityViewModel);
                }
            }

            return(View(entityViewModels));
        }