public string ValidateInstance(Instance instance) { if (string.IsNullOrEmpty(instance.InstanceName)) return Messages.EmptyInstanceName; if (Db.IsExistInstanceName(instance.InstanceName)) return Messages.ExistsInstanceName; return null; }
public MethodResult<int> CreateInstance(string instanceName) { using (var transaction = new TransactionScope()) { var instance = new Instance { InstanceName = instanceName }; var validateError = ValidateInstance(instance); if (!string.IsNullOrEmpty(validateError)) return new MethodResult<int> { ErrorMessage = validateError }; Db.Save(instance); Db.SetInstanceId(instance.InstanceId); var adminRoleId = InsertSystemRoles(instance.InstanceId); Db.AddUserInstance(); Db.AddUserRole(adminRoleId); transaction.Complete(); return new MethodResult<int>(instance.InstanceId); } }