public bool UpdateSettings(UserMaster obj) { bool isDone = false; if (obj.Id <= 0) { throw new Exception("<li>Invalid User selected</li>"); } string errorMessage = obj.CheckValidation(); if (errorMessage.Trim().Length > 0) { throw new ApplicationException(errorMessage); } //Starting Transaction using (TransactionDecorator transaction = new TransactionDecorator()) { //Saving Data by calling Dao Method isDone = daoObject.UpdateSettings(obj); //If Id is returned as Zero from Data Layer, then throwing Exception and rolling back the Transaction if (!isDone) { throw new Exception("Error Saving Data.", null); } //If no Error, then Commiting Transaction transaction.Complete(); } return(isDone); }
public int SaveData(UserMaster obj) { int Id = 0; string errorMessage = ""; try { //Checking the Validations string validationResult = obj.CheckValidation(); if (validationResult.Length > 0) { throw new ApplicationException(validationResult); } //Checking if the Name already exists if (common.CheckValueAlreadyExists(obj.Id, "NAME", obj.Name, obj.DatabaseTableName)) { errorMessage += ("<li>User Name already exists.</li>"); } //Checking if the Email already exists if (common.CheckValueAlreadyExists(obj.Id, "EMAIL_ID", obj.EmailId, obj.DatabaseTableName)) { errorMessage += ("<li>Email Id already exists.</li>"); } //Checking if the Mobile Number already exists if (common.CheckValueAlreadyExists(obj.Id, "MOBILE_NO", obj.MobileNo, obj.DatabaseTableName)) { errorMessage += ("<li>Mobile No. already exists.</li>"); } if (obj.Id != 0) { if (common.CheckRowVersion(obj.Id, obj.RowVersion, obj.DatabaseTableName) == false) { errorMessage += ("<li>Record has been modified by some other user. Please reload the record and then modify.</li>"); } } if (errorMessage != "") { throw new ApplicationException(errorMessage); } //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); }