public Car GetCar(int carId) { /*try {*/ return ExecuteFaultHandledOperation(() => { ICarRepository carRepository = _dataRepositoryFactory.GetDataRepository<ICarRepository>(); Car carEntity = carRepository.Get(carId); if (carEntity == null) { NotFoundException ex = new NotFoundException(string.Format("Car with ID of {0} is not in the database", carId)); throw new FaultException<NotFoundException>(ex, ex.Message); } return carEntity; }); /*} catch (FaultException ex) { throw ex; } catch (Exception ex) { throw new FaultException(ex.Message); } */ }
public IEnumerable<SalesOrder> GetSalesOrderHistory(string loginEmail) { return ExecuteFaultHandledOperation(() => { IAccountRepository accountRepository = _dataRepositoryFactory.GetDataRepository<IAccountRepository>(); // IRentalRepository salesOrderRepository = _DataRepositoryFactory.GetDataRepository<ISalesOrderRepository>(); Account account = accountRepository.GetByLogin(loginEmail); if (account == null) { NotFoundException ex = new NotFoundException(string.Format("No account found for login '{0}'.", loginEmail)); throw new FaultException<NotFoundException>(ex, ex.Message); } ValidateAuthorization(account); //IEnumerable<SalesOrder> rentalHistory = salesOrderRepository.GetSalesOrderHistoryByAccount(account.AccountId); var SalesOrderList = new List<SalesOrder> { new SalesOrder {SalesOrderId = 1, AccountId = 1, Amount = 18.0000M}, new SalesOrder {SalesOrderId = 2, AccountId = 1, Amount = 19.0000M}, new SalesOrder {SalesOrderId = 3, AccountId = 1, Amount = 10.0000M} }; return SalesOrderList; }); }
protected override Account LoadAuthorizationValidationAccount(string loginName) { IAccountRepository accountRepository = _DataRepositoryFactory.GetDataRepository<IAccountRepository>(); Account authAcct = accountRepository.GetByLogin(loginName); if (authAcct == null) { NotFoundException ex = new NotFoundException(string.Format("Cannot find account for login name {0} to use security", loginName)); throw new FaultException<NotFoundException>(ex, ex.Message); } return authAcct; }
protected override Account LoadAuthorizationValidationAccount(string loginName) { var accountRepository = _dataRepositoryFactory.GetDataRepository<IAccountRepository>(); var authAccount = accountRepository.GetByLogin(loginName); if (authAccount == null) { var ex = new NotFoundException($"Cannot find account with such a {loginName}"); throw new FaultException<NotFoundException>(ex, ex.Message); } return authAccount; }
public Doctor GetDoctor(int id) { return ExecuteFaultHandledOperation(() => { var doctorRepository = _dataRepositoryFactory.GetDataRepository<IDoctorRepository>(); var doctor = doctorRepository.Get(id); if (doctor == null) { var ex = new NotFoundException(string.Format("Doctor with Id {0} not available.", id)); throw new FaultException<NotFoundException>(ex, ex.Message); } return doctor; }); }
public Account GetAccountDetail(int id) { return ExecuteFaultHandledOperation(() => { var accountRepository = _dataRepositoryFactory.GetDataRepository<IAccountRepository>(); var account = accountRepository.Get(id); if (account == null) { var ex = new NotFoundException(string.Format("Account with Id {0} not available.", id)); throw new FaultException<NotFoundException>(ex, ex.Message); } return account; }); }
// [PrincipalPermission(SecurityAction.Demand, Role = Security.BomAdminRole)] // [PrincipalPermission(SecurityAction.Demand, Role = Security.BomUserRole)] public Supplier GetSupplier(int supplierId) { return ExecuteFaultHandledOperation(() => { ISupplierRepository repo = _dataRepositoryFactory.GetDataRepository<ISupplierRepository>(); var supplier = repo.Get(supplierId); if (supplier == null) { var ex = new NotFoundException(String.Format("Supplier with ID = {0} not found in the database", supplierId)); throw new FaultException<NotFoundException>(ex, ex.Message); } return supplier; }); }
public Entities.Account GetCustomerAccountInfo(string loginEmail) { return ExecuteFaultHandledOperation(() => { IAccountRepository accountRepository = _DataRepositoryFactory.GetDataRepository<IAccountRepository>(); Account accountEntity = accountRepository.GetByLogin(loginEmail); if (accountEntity == null) { NotFoundException ex = new NotFoundException(string.Format("Account with login {0} is not in database", loginEmail)); throw new FaultException<NotFoundException>(ex, ex.Message); } ValidationAuthorization(accountEntity); return accountEntity; }); }
public void DeleteStyle(int MerretStleID) { ExecuteFaultHandledOperation(() => { var styleRepository = _dataRepositoryFactory.GetDataRepository<IStyleRepository>(); var styleEntity = styleRepository.Get(MerretStleID); if (styleEntity == null) { NotFoundException ex = new NotFoundException(string.Format("Resource Master with Id {0} is not in the database. ", MerretStleID)); throw new FaultException<NotFoundException>(ex, ex.Message); } styleRepository.Remove(MerretStleID); }); }
public Style GetStyle(int MerretStleID) { return ExecuteFaultHandledOperation(() => { IStyleRepository styleRepository = _dataRepositoryFactory.GetDataRepository<IStyleRepository>(); Style resourceMasterEntity = styleRepository.Get().Where(r => r.MerretStyleID == MerretStleID).FirstOrDefault(); if (resourceMasterEntity == null) { NotFoundException ex = new NotFoundException(string.Format("Style ID {0} is not in the database. ", MerretStleID)); throw new FaultException<NotFoundException>(ex, ex.Message); } return resourceMasterEntity; }); }
public void DeleteProduct(int ProductId) { ExecuteFaultHandledOperation(() => { var productRepository = _dataRepositoryFactory.GetDataRepository<IProductRepository>(); var accountEntity = productRepository.Get(ProductId); if (accountEntity == null) { NotFoundException ex = new NotFoundException(string.Format("Product with Id {0} is not in the database. ", ProductId)); throw new FaultException<NotFoundException>(ex, ex.Message); } productRepository.Remove(ProductId); }); }
public Account GetClientAccountInfo(string loginEmail) { return ExecuteFaultHandledOperation(() => { var accountRepository = _dataRepositoryFactory.GetDataRepository<IAccountRepository>(); var account = accountRepository.GetByLogin(loginEmail); if (account == null) { var ex = new NotFoundException($"Cannot find account with such a {loginEmail}"); throw new FaultException<NotFoundException>(ex, ex.Message); } ValidateAuthorization(account); return account; }); }
/// <summary> /// Get an entity of type CultureCountryCode /// </summary> /// <param name="cultureCountryCodeId"></param> /// <returns></returns> public CultureCountryCode GetCultureCountryCode(int cultureCountryCodeId) { return ExecuteFaultHandledOperation(() => { var productRepositoryFactory = _dataRepositoryFactory.GetDataRepository<ICultureCountryCodeRepository>(); CultureCountryCode CultureCountryCodeEntity = productRepositoryFactory.Get(cultureCountryCodeId); if (CultureCountryCodeEntity == null) { NotFoundException ex = new NotFoundException(string.Format("Culture Country with Id {0} is not in the database. ", cultureCountryCodeId)); throw new FaultException<NotFoundException>(ex, ex.Message); } return CultureCountryCodeEntity; }); }
//[PrincipalPermission(SecurityAction.Demand, Role = Security.eCommerceAdminRole)] //[PrincipalPermission(SecurityAction.Demand, Name = Security.eCommerceUser)] public ResourceMaster GetMasterResource(string resourceKey) { return ExecuteFaultHandledOperation(() => { IResourceMasterRepository resourceMasterRepository = _dataRepositoryFactory.GetDataRepository<IResourceMasterRepository>(); ResourceMaster resourceMasterEntity = resourceMasterRepository.Get().Where(r => r.Name == resourceKey).FirstOrDefault(); if (resourceMasterEntity == null) { NotFoundException ex = new NotFoundException(string.Format("Master Resource with name {0} is not in the database. ", resourceKey)); throw new FaultException<NotFoundException>(ex, ex.Message); } return resourceMasterEntity; }); }
public IEnumerable<Rental> GetRentalHistory(string loginEmail) { return ExecuteFaultHandledOperation(() => { IAccountRepository accountRepository = _dataRepositoryFactory.GetDataRepository<IAccountRepository>(); IRentalRepository rentalRepository = _dataRepositoryFactory.GetDataRepository<IRentalRepository>(); Account account = accountRepository.GetByLogin(loginEmail); if (account == null) { NotFoundException ex = new NotFoundException(string.Format("No account found for login '{0}'", loginEmail)); throw new FaultException<NotFoundException>(ex, ex.Message); } ValidateAuthorization(account); IEnumerable<Rental> rentalHistory = rentalRepository.GetRentalHistoryByAccount(account.AccountId); return rentalHistory; }); }
public Product GetProduct(int productId) { return ExecuteFaultHandledOperation(() => { var productRepositoryFactory = _dataRepositoryFactory.GetDataRepository<IProductRepository>(); Product productEntity = productRepositoryFactory.Get(productId); if (productEntity == null) { NotFoundException ex = new NotFoundException(string.Format("Product with Id {0} is not in the database. ", productId)); throw new FaultException<NotFoundException>(ex, ex.Message); } return productEntity; }); }
public IEnumerable<Hired> GetHiringHistory(string loginEmail) { return ExecuteFaultHandledOperation(() => { var accountRepository = _dataRepositoryFactory.GetDataRepository<IAccountRepository>(); var hiringRepository = _dataRepositoryFactory.GetDataRepository<IHiringRepository>(); var account = accountRepository.GetByLogin(loginEmail); if (account == null) { var ex = new NotFoundException($"No Account with such an {loginEmail} was found!"); throw new FaultException<NotFoundException>(ex, ex.Message); } ValidateAuthorization(account); var hiringHistory = hiringRepository.GetHiringHistoryByAccount(account.AccountId); return hiringHistory; }); }
//Get my Order repo from the data repository factory public OrderStacker.Business.Entities.Order GetOrder(int orderId) { //Using this Pattern of sending codesnippets into the ExecuteFaultHandledOperation //means that my GENERAL error handling is in only one place return ExecuteFaultHandledOperation(() => { IOrderRepository orderRepository = _DataRepositoryFactory.GetDataRepository<IOrderRepository>(); Order orderEntity = orderRepository.Get(orderId); if (orderEntity == null) { NotFoundException ex = new NotFoundException(string.Format("Order with Id of {0} was not found", orderId)); //Because this fault is in WCF, we have to throw a SOAP fault up the client throw new FaultException<NotFoundException>(ex, ex.Message); //throwing this will not break the proxy either } return orderEntity; } ); }
public Developer GetDeveloper(int developerId) { return ExecuteFaultHandledOperation(() => { var developerRepository = _dataRepositoryFactory.GetDataRepository<IDeveloperRepository>(); var developerEntity = developerRepository.Get(developerId); if (developerEntity == null) { var ex = new NotFoundException($"The Developer with such an ID {developerId} is not found in the database"); // This is how one throws an exception in WCF so that the Client whose on a different machine can caught this exception as // an SOAP message ( SOAP-Fault wrap). // FaultException<T> l'l not Fault the proxy thus that proxy l'l still be reusable if needed. throw new FaultException<NotFoundException>(ex, ex.Message); } return developerEntity; }); }
public void CancelReservation(int reservationId) { ExecuteFaultHandledOperation(() => { IReservationRepository reservationRepository = _DataRepositoryFactory.GetDataRepository<IReservationRepository>(); Reservation reservation = reservationRepository.Get(reservationId); if (reservation == null) { NotFoundException ex = new NotFoundException(string.Format("No reservation found for ID '{0}'", reservationId)); throw new FaultException<NotFoundException>(ex, ex.Message); } ValidateAuthorization(reservation); reservationRepository.Remove(reservationId); }); }
public CustomerFile[] GetCustomerFiles() { return ExecuteFaultHandledOperation(() => { IAccountRepository accountRepository = _DataRepositoryFactory.GetDataRepository<IAccountRepository>(); ICustomerFileRepository customerFileRepository = _DataRepositoryFactory.GetDataRepository<ICustomerFileRepository>(); Account account = accountRepository.GetByLogin(_loginName); if (account == null) { NotFoundException ex = new NotFoundException(string.Format("No account found for login {0}", _loginName)); throw new FaultException<NotFoundException>(ex, ex.Message); } ValidationAuthorization(account); IEnumerable<CustomerFile> files = customerFileRepository.GetCustomerFilesByAccount(account); CustomerFile[] filesArray = files.ToArray<CustomerFile>(); return filesArray; }); }
public Rental GetRental(int rentalId) { return ExecuteFaultHandledOperation( () => { IAccountRepository accountRepository = _DataRepositoryFactory.GetDataRepository<IAccountRepository>(); IRentalRepository rentalRepository = _DataRepositoryFactory.GetDataRepository<IRentalRepository>(); Rental rental = rentalRepository.Get(rentalId); if (rental == null) { NotFoundException ex = new NotFoundException(string.Format("No rental record for id '{0}'", rentalId)); throw new FaultException<NotFoundException>(ex, ex.Message); } ValidateAuthorization(rental); return rental; }); }
public Reservation MakeReservation(string loginEmail, int carId, DateTime rentalDate, DateTime returnDate) { IAccountRepository accountRepository = _DataRepositoryFactory.GetDataRepository<IAccountRepository>(); IReservationRepository reservationRepository = _DataRepositoryFactory.GetDataRepository<IReservationRepository>(); Account account = accountRepository.GetByLogin(loginEmail); if (account == null) { NotFoundException ex = new NotFoundException(string.Format("No account found for login '{0}'", loginEmail)); throw new FaultException<NotFoundException>(ex, ex.Message); } ValidateAuthorization(account); Reservation reservation = new Reservation() { AccountId = account.AccountId, CarId = carId, RentalDate = rentalDate, ReturnDate = returnDate }; Reservation savedEntity = reservationRepository.Add(reservation); return savedEntity; }
public void ExecuteRentalFromReservation(int reservationId) { IAccountRepository accountRepository = _DataRepositoryFactory.GetDataRepository<IAccountRepository>(); IReservationRepository reservationRepository =_DataRepositoryFactory.GetDataRepository<IReservationRepository>(); ICarRentalEngine carRentalEngine = _BusinessEngineFactory.GetBusinessEngine<ICarRentalEngine>(); Reservation reservation = reservationRepository.Get(reservationId); if (reservation == null) { NotFoundException ex = new NotFoundException(string.Format("Reservation {0} is not found", reservationId)); throw new FaultException<NotFoundException>(ex, ex.Message); } Account account = accountRepository.Get(reservation.AccountId); if (account == null) { NotFoundException ex = new NotFoundException(string.Format("No account found for account ID '{0}'", reservation.AccountId)); throw new FaultException<NotFoundException>(ex, ex.Message); } try { Rental rental = carRentalEngine.RentCarToCustomer(account.LoginEmail, reservation.CarId, reservation.RentalDate, reservation.ReturnDate); } catch (UnableToRentForDateException ex) { throw new FaultException<UnableToRentForDateException>(ex, ex.Message); } catch (CarCurrentlyRentedException ex) { throw new FaultException<CarCurrentlyRentedException>(ex, ex.Message); } catch (NotFoundException ex) { throw new FaultException<NotFoundException>(ex, ex.Message); } reservationRepository.Remove(reservation); }
public CustomerReservationData[] GetCustomerReservations(string loginEmail) { return ExecuteFaultHandledOperation(() => { IAccountRepository accountRepository =_DataRepositoryFactory.GetDataRepository<IAccountRepository>(); IReservationRepository reservationRepository = _DataRepositoryFactory.GetDataRepository<IReservationRepository>(); Account account = accountRepository.GetByLogin(loginEmail); if (account == null) { NotFoundException ex = new NotFoundException(string.Format("No account found for login '{0}'", loginEmail)); throw new FaultException<NotFoundException>(ex, ex.Message); } ValidateAuthorization(account); List<CustomerReservationData> reservationData = new List<CustomerReservationData>(); IEnumerable<CustomerReservationInfo> reservationInfoSet = reservationRepository.GetCustomerOpenReservationInfo(account.AccountId); foreach (var reservationInfo in reservationInfoSet) { reservationData.Add(new CustomerReservationData() { ReservationId = reservationInfo.Reservation.ReservationId, Car = reservationInfo.Car.Color + " " + reservationInfo.Car.Year + " " + reservationInfo.Car.Description, CustomerName = reservationInfo.Customer.FirstName + " " + reservationInfo.Customer.LastName, RentalDate = reservationInfo.Reservation.RentalDate, ReturnDate = reservationInfo.Reservation.ReturnDate }); } return reservationData.ToArray(); }); }
public Rental RentCarToCustomer(string loginEmail, int carId, DateTime rentalDate, DateTime dateDueBack) { return ExecuteFaultHandledOperation(() => { if (rentalDate > DateTime.Now) { UnableToRentForDateException ex = new UnableToRentForDateException(string.Format("Cannot rent for date {0} yet.", rentalDate.ToShortDateString())); throw new FaultException<UnableToRentForDateException>(ex, ex.Message); } IAccountRepository accountRepository = _DataRepositoryFactory.GetDataRepository<IAccountRepository>(); IRentalRepository rentalRepository = _DataRepositoryFactory.GetDataRepository<IRentalRepository>(); ICarRentalEngine carRentalEngine = _BusinessEngineFactory.GetBusinessEngine<ICarRentalEngine>(); bool carIsRented = carRentalEngine.IsCarCurrentlyRented(carId); if (carIsRented) { CarCurrentlyRentedException ex = new CarCurrentlyRentedException(string.Format("Car {0} is already rented.", carId)); throw new FaultException<CarCurrentlyRentedException>(ex, ex.Message); } Account account = accountRepository.GetByLogin(loginEmail); if (account == null) { NotFoundException ex = new NotFoundException(string.Format("No account found for login '{0}'.", loginEmail)); throw new FaultException<NotFoundException>(ex, ex.Message); } Rental rental = new Rental() { AccountId = account.AccountId, CarId = carId, DateRented = rentalDate, DateDue = dateDueBack }; Rental savedEntity = rentalRepository.Add(rental); return savedEntity; }); }
public void ExecuteRentalFromReservation(int reservationId) { ExecuteFaultHandledOperation(() => { IAccountRepository accountRepository = _DataRepositoryFactory.GetDataRepository<IAccountRepository>(); IReservationRepository reservationRepository = _DataRepositoryFactory.GetDataRepository<IReservationRepository>(); Reservation reservation = reservationRepository.Get(reservationId); if (reservation == null) { NotFoundException ex = new NotFoundException(string.Format("Reservation {0} is not found.", reservationId)); throw new FaultException<NotFoundException>(ex, ex.Message); } Account account = accountRepository.Get(reservation.AccountId); if (account == null) { NotFoundException ex = new NotFoundException(string.Format("No account found for account ID '{0}'.", reservation.AccountId)); throw new FaultException<NotFoundException>(ex, ex.Message); } RentCarToCustomer(account.LoginEmail, reservation.CarId, reservation.RentalDate, reservation.ReturnDate); reservationRepository.Remove(reservation); }); }
public void DeleteCultureCountryCode(int cultureCountryCodeId) { ExecuteFaultHandledOperation(() => { var cultureCountryCodeRepository = _dataRepositoryFactory.GetDataRepository<ICultureCountryCodeRepository>(); var accountEntity = cultureCountryCodeRepository.Get(cultureCountryCodeId); if (accountEntity == null) { NotFoundException ex = new NotFoundException(string.Format("Product with Id {0} is not in the database. ", cultureCountryCodeId)); throw new FaultException<NotFoundException>(ex, ex.Message); } cultureCountryCodeRepository.Remove(cultureCountryCodeId); }); }
public Reservation GetReservation(int reservationId) { return ExecuteFaultHandledOperation(() => { var accountRepository = _DataRepositoryFactory.GetDataRepository<IAccountRepository>(); var reservationRepository = _DataRepositoryFactory.GetDataRepository<IReservationRepository>(); var reservation = reservationRepository.Get(reservationId); if (reservation == null) { var ex = new NotFoundException(string.Format("No reservation record found for id '{0}'.", reservationId)); throw new FaultException<NotFoundException>(ex, ex.Message); } ValidateAuthorization(reservation); return reservation; }); }
protected override Account LoadAuthorizationValidationAccount(string loginName) { var accountRepository = _dataRepositoryFactory.GetDataRepository<IAccountRepository>(); var account = accountRepository.GetByLogin(loginName); if(account==null) { var ex = new NotFoundException(string.Format("Can't find account for login {0}",loginName)); throw new FaultException<NotFoundException>(ex,ex.Message); } return account; }