/// <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); } }
private void InitCustomServices() { try { // Cargar los modelos de datos y verificar los ensamblados ServiceDataAccess serviceDataAccess = new ServiceDataAccess(); Collection <ServiceEntity> services = serviceDataAccess.LoadAll(true); foreach (ServiceEntity service in services) { string assemblyFileName = service.PathAssemblyServer; if (assemblyFileName != null) { if (File.Exists(Path.Combine(ServiceBuilder.AssembliesFolder, assemblyFileName))) { Type[] servicesTypes = ServiceBuilder.GetCustomServiceTypes(assemblyFileName); Binding serviceBinding = new BasicHttpBinding(); if (PublishCustomService(servicesTypes[0], servicesTypes[1], serviceBinding)) { Debug.WriteLine("SUCCESS : custom service published."); } else { Debug.WriteLine("FAILURE : trying to publish custom service."); } } else { CustomerServiceDataDataAccess customerServiceData = new CustomerServiceDataDataAccess(); CustomerServiceDataEntity customerService = customerServiceData.Load(service.IdCustomerServiceData, true); ServiceBuilder builder = new ServiceBuilder(); service.Deployed = false; customerService.Service = service; builder.BuildAndImplementCustomService(customerService, serverSession); } } } } catch (DataException dataError) { Debug.WriteLine("ERROR : Data exception running infrastructure services. MESSAGE : " + dataError.Message); } catch (IOException ioError) { Debug.WriteLine("ERROR : IO error running infrastructure services. MESSAGE : " + ioError.Message); } }
public CustomerServiceData() { customerservicedataDataAccess = new CustomerServiceDataDataAccess(); }