/// <summary> /// Function to save a DataModelEntity to the database. /// </summary> /// <param name="dataModelEntity">DataModelEntity to save</param> /// <param name="session">User's session identifier.</param> /// <returns>null if the DataModelEntity was saved successfully, the same DataModelEntity otherwise</returns> /// <exception cref="ArgumentNullException"> /// if <paramref name="dataModelEntity"/> is null. /// </exception> /// <exception cref="UtnEmallBusinessLogicException"> /// If an UtnEmallDataAccessException occurs in DataModel. /// </exception> public DataModelEntity Save(DataModelEntity dataModelEntity, string session) { bool permited = ValidationService.Instance.ValidatePermission(session, "save", "DataModel"); if (!permited) { ExceptionDetail detail = new ExceptionDetail(new UtnEmall.Server.BusinessLogic.UtnEmallPermissionException("The user hasn't permissions to save an entity")); throw new FaultException <ExceptionDetail>(detail); } if (!Validate(dataModelEntity)) { return(dataModelEntity); } try { // Check that the service is not deployed if (dataModelEntity.Deployed) { dataModelEntity.Errors.Add(new Error("DataModel Deployed", "", "The data model is already deployed. Can not be saved.")); return(dataModelEntity); } // Check that there isn't related custom services if (dataModelEntity.Id > 0) { CustomerServiceDataDataAccess customerServiceData = new CustomerServiceDataDataAccess(); // Get all customer services where IdDataModel is the same as us int referencedServices = customerServiceData.LoadWhere(CustomerServiceDataEntity.DBIdDataModel, dataModelEntity.Id, false, OperatorType.Equal).Count; // If there are customer services it is an error if (referencedServices > 0) { dataModelEntity.Errors.Add(new Error("DataModel Deployed", "", "The data model has related customer services. Can not be updated.")); return(dataModelEntity); } } // Save dataModelEntity using data access object datamodelDataAccess.Save(dataModelEntity); return(null); } catch (UtnEmallDataAccessException utnEmallDataAccessException) { throw new UtnEmall.Server.BusinessLogic.UtnEmallBusinessLogicException(utnEmallDataAccessException.Message, utnEmallDataAccessException); } }
/// <summary> /// Get collection of all customerServiceDataEntity that comply with certain pattern /// </summary> /// <param name="propertyName">property of customerServiceDataEntity</param> /// <param name="expValue">pattern</param> /// <param name="loadRelation">true to load the relations</param> /// <param name="session">User's session identifier.</param> /// <returns>Collection of CustomerServiceDataEntity</returns> /// <exception cref="ArgumentNullException"> /// if <paramref name="propertyName"/> is null or empty. /// <exception cref="ArgumentNullException"> /// if <paramref name="expValue"/> is null or empty. /// </exception> /// <exception cref="UtnEmallBusinessLogicException"> /// If an UtnEmallDataAccessException occurs in DataModel. /// </exception> public Collection <CustomerServiceDataEntity> GetCustomerServiceDataWhere(string propertyName, object expValue, bool loadRelation, OperatorType operatorType, string session) { bool permited = ValidationService.Instance.ValidatePermission(session, "read", "CustomerServiceData"); if (!permited) { ExceptionDetail detail = new ExceptionDetail(new UtnEmall.Server.BusinessLogic.UtnEmallPermissionException("The user hasn't permissions to read an entity")); throw new FaultException <ExceptionDetail>(detail); } try { return(customerservicedataDataAccess.LoadWhere(propertyName, expValue, loadRelation, operatorType)); } catch (UtnEmallDataAccessException utnEmallDataAccessException) { throw new UtnEmall.Server.BusinessLogic.UtnEmallBusinessLogicException(utnEmallDataAccessException.Message, utnEmallDataAccessException); } }