AutoMapperIntro.Controllers.Manager.GetAllManufacturers C# (CSharp) Method

GetAllManufacturers() public method

public GetAllManufacturers ( ) : IEnumerable
return IEnumerable
        public IEnumerable<ManufacturerBase> GetAllManufacturers()
        {
            // Fetch from the persistent store
            var fetchedObjects = ds.Manufacturers.OrderBy(man => man.Name);

            // Prepare and return the view model objects
            return Mapper.Map<IEnumerable<ManufacturerBase>>(fetchedObjects);

            /*
            // Prepare the view model objects...

            // Create a collection
            var manufacturers = new List<ManufacturerBase>();

            // Go through the fetch results
            foreach (var item in fetchedObjects)
            {
                var man = new ManufacturerBase();
                man.Id = item.Id;
                man.Name = item.Name;
                man.Country = item.Country;
                man.YearStarted = item.YearStarted;
                manufacturers.Add(man);
            }

            // Return the result
            return manufacturers;
            */
        }

Usage Example

示例#1
0
 //
 // GET: /Manufacturers/
 public ActionResult Index()
 {
     return(View(m.GetAllManufacturers()));
 }