public string RegisterCarRental(RentalRegistration rentalRegistration)
 {
     Console.WriteLine("RegisterCarRental");
     using (DataClassesRentalDataContext ctx = new DataClassesRentalDataContext())
     {
         Rental rentalToInsert;
         rentalToInsert = new Rental();
         rentalToInsert.CustomerID = rentalRegistration.CustomerID;
         rentalToInsert.CarID = rentalRegistration.CarID;
         rentalToInsert.Comments = rentalRegistration.Comments;
         ctx.Rental.InsertOnSubmit(rentalToInsert);
         ctx.SubmitChanges();
     }
     return "OK";
 }
Beispiel #2
0
        public string RegisterCarRental(RentalRegistration rentalRegistration)
        {
            Console.WriteLine("RegisterCarRental");

            if (rentalRegistration == null)
            {
                RentalRegisterFault fault;
                fault                  = new RentalRegisterFault();
                fault.FaultID          = 1;
                fault.FaultDescription = "Input is not valid, got null value";
                throw new FaultException <RentalRegisterFault>(fault, "");
            }

            try
            {
                using (DataClassesRentalDataContext ctx = new DataClassesRentalDataContext())
                {
                    Rental rentalToInsert;
                    rentalToInsert            = new Rental();
                    rentalToInsert.CustomerID = rentalRegistration.CustomerID;
                    rentalToInsert.CarID      = rentalRegistration.CarID;
                    rentalToInsert.Comments   = rentalRegistration.Comments;
                    ctx.Rental.InsertOnSubmit(rentalToInsert);

                    //throw new DivideByZeroException();

                    ctx.SubmitChanges();
                    Console.WriteLine(">SubmitChanges RegisterCarRental ");
                    return("OK");
                }
            }
            catch (Exception ex)
            {
                RentalRegisterFault fault;
                fault                  = new RentalRegisterFault();
                fault.FaultID          = 123;
                fault.FaultDescription = "An error occured while inserting the rental registration : " + ex.Message;
                throw new FaultException <RentalRegisterFault>(fault, "");
            }
        }