public int SaveData(Holiday obj) { int Id = 0; try { //Checking the Validations string validationResult = obj.CheckValidation(); if (validationResult.Length > 0) { throw new ApplicationException(validationResult); } //Starting Transaction using (TransactionDecorator transaction = new TransactionDecorator()) { //Saving Data by calling Dao Method Id = daoObject.SaveData(obj); //If Id is returned as Zero from Data Layer, then throwing Exception and rolling back the Transaction if (Id == 0 && obj.Id == 0) { throw new ApplicationException("Error Saving Data.", null); } //If Id is returned as Zero from Data Layer, then throwing Exception and rolling back the Transaction if (Id == 0 && obj.Id != 0) { throw new ApplicationException("Record has been modified by some other user. Please reload the record and then modify.", null); } //If no Error, then Commiting Transaction transaction.Complete(); } } catch (ApplicationException ex) { Id = 0; throw new ApplicationException(ex.Message, null); } return(Id); }