public Profile Save(Profile profile)
        {
            EFModel.QuickReceiptEntities ctx = new EFModel.QuickReceiptEntities();
            var dbProfile = Mapper.Map(profile);

            if (profile.Id > 0)
            {
                //update
                var existingProfile = (from p in ctx.Profiles
                                       where p.Id == profile.Id
                                       select p).FirstOrDefault();

                if (existingProfile == null)
                {
                    throw new ObjectNotFoundException("Profile with Id " + profile.Id.ToString() + " couldn't be found in the database.  No update was peformed");
                }

                ctx.ApplyCurrentValues<EFModel.Profile>("Profiles", dbProfile);
            }
            else
            {
                ctx.Profiles.AddObject(dbProfile);
            }

            ctx.SaveChanges();

            return Mapper.Map(dbProfile);
        }
        //
        // GET: /Profile/Create
        public ActionResult Create()
        {
            ViewBag.Categories = CategoryRepository.List();
            ViewBag.Types = TypeRepository.List();
            ViewBag.Items = ItemRepository.List();
            ViewBag.Issues = IssueRepository.List();

            Profile p = new Profile();
            return View(p);
        }
        public Profile Map(EFModel.Profile p)
        {
            Profile prof = new Profile();
            prof.Id = p.Id;
            prof.Name = p.Name;
            prof.Category = CategoryRepository.List().Where(x => x.Id == p.CategoryId).First();
            prof.Issue = IssueRepository.List().Where(x => x.Id == p.IssueId).First();
            prof.Item = ItemRepository.List().Where(x => x.Id == p.ItemId).First();
            prof.Type = TypeRepository.List().Where(x => x.Id == p.TypeId).First();

            return prof;
        }
        public EFModel.Profile Map(Profile p)
        {
            EFModel.Profile prof = new EFModel.Profile();
            prof.Id = p.Id;
            prof.Name = p.Name;
            prof.CategoryId = p.Category.Id;
            prof.IssueId = p.Issue.Id;
            prof.ItemId = p.Item.Id;
            prof.TypeId = p.Type.Id;

            return prof;
        }
        public ActionResult Create(Profile profile)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    profile = ProfileRepository.Save(profile);
                }
            }
            catch(Exception ex)
            {
                ModelState.AddModelError("Name", ex);
            }

            if (profile.Id != 0)
            {
                return RedirectToAction("Index");
            }

            return View(profile);
        }
        public ActionResult Edit(int id, Profile profile)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    profile = ProfileRepository.Save(profile);

                    return RedirectToAction("Index");
                }
            }
            catch(Exception ex)
            {
                return View("Error", new HandleErrorInfo(ex, "Profile", "Edit"));
            }

            return View(profile);
        }