Пример #1
0
        // GET: ArmyModels/Details

        public ActionResult Details(int id)
        {               // this will show the army info, but will also show a list of models that come with the army
                        // if this army is not owned by user and doesnt have role user is diverted.
            List <ArmyModelBLL> models = null;
            ArmyBLL             army   = null;

            try
            {            // using is used because we use an SQL connection which is high in resources
                using (ContextBLL ctx = new ContextBLL())
                {
                    army = ctx.ArmyFindByID(id);
                    if (army == null)
                    {                    // If no record is returned we divert to a custom error screen.
                        return(View("NotFound"));
                    }
                    models = ctx.ArmyModelsFindByArmyID(army.ArmyID, Constants.DefaultPageNumber, Constants.DefaultPageSize);
                }
            }
            catch (Exception oops)
            {            // if the connection fails or something else goes wrong we log the error and divert.
                Error.Log(oops);
                return(View("Error", oops));
            }
            FullArmyData item = new FullArmyData(army, models);            // item is an instance of FullArmyData!

            item.models = models;
            if (!IsMineOrAdmin(item))
            {            // if user should not see this we divert him.
                return(View("Porpoise"));
            }
            return(View(item));
        }