public BookedService createForFamilyMember(Guid serviceID, Guid familyMemberID, Guid deadPersonID)
        {
            try
            {
                BookedService bookedService = null;

                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    Service    service    = new ServicesRepository(db).getByID(serviceID.ToString());
                    DeadPerson deadPerson = new DeadPersonRepository(db).getByID(deadPersonID.ToString());

                    bookedService = new BookedService
                    {
                        BookedServiceID  = Guid.NewGuid(),
                        Name             = service.Name,
                        Description      = service.Description,
                        FamilyMemberID   = familyMemberID,
                        PriceGross       = service.PriceGross,
                        BurialPlaceID    = deadPerson.BurialPlaceID,
                        IsFinished       = false,
                        IsPaid           = false,
                        CreationDateTime = DateTime.Now
                    };

                    new BookedServicesRepository(db).create(bookedService);
                    db.SaveChanges();
                }

                return(bookedService);
            }
            catch (Exception ex) { }
            return(null);
        }
Exemple #2
0
 public List <DeadPerson> getBy(Func <DeadPerson, bool> whereClausule)
 {
     try
     {
         List <DeadPerson> listDeadPerson = new List <DeadPerson>();
         using (ApplicationDbContext db = new ApplicationDbContext())
         {
             listDeadPerson = new DeadPersonRepository(db).getBy(whereClausule);
         }
         return(listDeadPerson);
     }
     catch (Exception ex) { }
     return(new List <DeadPerson>());
 }
Exemple #3
0
 public DeadPerson getByID(Guid id)
 {
     try
     {
         DeadPerson deadPerson = null;
         using (ApplicationDbContext db = new ApplicationDbContext())
         {
             deadPerson = new DeadPersonRepository(db).getByID(id.ToString());
         }
         return(deadPerson);
     }
     catch (Exception ex) { }
     return(null);
 }
Exemple #4
0
 public List <DeadPerson> getAll()
 {
     try
     {
         List <DeadPerson> listDeadPerson = new List <DeadPerson>();
         using (ApplicationDbContext db = new ApplicationDbContext())
         {
             listDeadPerson = new DeadPersonRepository(db).getAll();
         }
         return(listDeadPerson);
     }
     catch (Exception ex) { }
     return(new List <DeadPerson>());
 }
Exemple #5
0
        /*
         *     internal List<DeadPerson> getBy(Func<DeadPerson, bool> p)
         *     {
         *         throw new NotImplementedException();
         *     }
         */


        public void processPayment(Guid deadPersonID, Guid familyMemberID)
        {
            try
            {
                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    using (var transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            DeadPerson deadPerson = new DeadPersonRepository(db).getByID(deadPersonID.ToString());

                            if (deadPerson.FamilyMemberID.Value != familyMemberID)
                            {
                                throw new Exception("Family member is allowed to edit only dead person that is under him");
                            }

                            DateTime?nextPaymentDate = deadPerson.BurialPlace.FuturePaymentDate;

                            if (nextPaymentDate.HasValue)
                            {
                                deadPerson.BurialPlace.PaymentDate = nextPaymentDate.Value;
                            }
                            else
                            {
                                deadPerson.BurialPlace.PaymentDate = DateTime.Now.AddDays(deadPerson.BurialPlace.PaymentClass.ExtraDaysForPaymentMade);
                            }

                            new DeadPersonRepository(db).update(deadPerson);

                            db.SaveChanges();
                            transaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            transaction.Rollback();
                        }
                    }
                }
            }
            catch (Exception ex) { }
        }