public BurialPlaceBooker createBookingForFamilyMember(ApplicationUser familyMemberUser, Guid burialPlaceID)
        {
            BurialPlaceBooker booker = null;

            try
            {
                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    BurialPlaceBookerRepository repo    = new BurialPlaceBookerRepository(db);
                    List <BurialPlaceBooker>    bookers = repo.getBy(x => x.FamilyMemberID.HasValue && x.FamilyMemberID.Equals(familyMemberUser.FamilyMemberID));
                    booker = bookers.Count > 0 ? bookers[0] : new BurialPlaceBooker();

                    booker.BurialPlaceID  = burialPlaceID;
                    booker.FamilyMemberID = familyMemberUser.FamilyMemberID;

                    // update
                    if (bookers.Count > 0)
                    {
                        repo.update(booker);
                    }
                    // create new
                    else
                    {
                        booker.BurialPlaceBookerID = Guid.NewGuid();
                        repo.create(booker);
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception ex) { }
            return(booker);
        }
 public List <BurialPlace> getForBooking()
 {
     try
     {
         List <BurialPlace> listBurialPlace = new List <BurialPlace>();
         using (ApplicationDbContext db = new ApplicationDbContext())
         {
             List <BurialPlaceBooker> listBurialPlaceBooker = new BurialPlaceBookerRepository(db).getAll();
             List <Guid> listBurialPlaceIDsToNotInclude     = listBurialPlaceBooker.Select(x => x.BurialPlaceID).ToList();
             listBurialPlace = new BurialPlaceRepository(db).getBy(x => !listBurialPlaceIDsToNotInclude.Contains(x.BurialPlaceID));
         }
         return(listBurialPlace);
     }
     catch (Exception ex) { }
     return(new List <BurialPlace>());
 }
 public BurialPlace getByFamilyMemberID(Guid familyMemberID)
 {
     try
     {
         BurialPlace burialPlace = null;
         using (ApplicationDbContext db = new ApplicationDbContext())
         {
             var burialPlaceBookers = new BurialPlaceBookerRepository(db).getBy(x => x.FamilyMemberID.HasValue && x.FamilyMemberID.Value.Equals(familyMemberID));
             if (burialPlaceBookers != null && burialPlaceBookers.Count > 0)
             {
                 burialPlace = burialPlaceBookers[0].BurialPlace;
             }
         }
         return(burialPlace);
     }
     catch (Exception ex) { }
     return(null);
 }
        public void cancelBooking(Guid familyMemberID)
        {
            try
            {
                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    BurialPlaceBookerRepository repo = new BurialPlaceBookerRepository(db);

                    List <BurialPlaceBooker> bookers = repo.getBy(x => x.FamilyMemberID.HasValue && x.FamilyMemberID.Equals(familyMemberID));

                    foreach (var booker in bookers)
                    {
                        repo.delete(booker);
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception ex) { }
        }